template<typename T, typename UnaryGenerator>
impl-dfn-deferred-range generate(T start, UnaryGenerator generator);

Creates a generator-pipe.

Parameters

  • start - the first element of the range which is to be created using the given generator.

  • generator - the generator to be used to create the range. It is a callable entity with the following signature:

    - T sig(T input);

    Each consecutive item is created by passing the current item:

     T next = generator(current); //initially current is start.

Return

A deferred-range of infinite size. Since the returned range is an infinite range, it can be used with take() or take_while() processor-pipe.

Example

#include <iostream>
#include <vector>
#include <foam/composition/pipeline.h>

int main()
{
    using namespace foam::composition;

    auto numbers = generate(10, [](int i) { return i + 5; }) 
                 | take_while([](int i) { return i < 30; } ); 
    for(int i : numbers)
        std::cout << i << " ";
}

Output

5 10 15 20 25

Other pipes