Package sage :: Package combinat :: Module generator
[hide private]
[frames] | no frames]

Module generator

source code

Functions [hide private]
 
concat(gens)
Returns a generator that is the concatenation of the generators in the list.
source code
 
map(f, gen)
Returns a generator that returns f(g) for g in gen.
source code
 
element(element, n=1)
Returns a generator that yield a single element n times.
source code
 
select(f, gen)
Returns a generator for all the elements g of gen such that f(g) is True.
source code
 
successor(initial, succ)
Given an initial value and a successor function, yeild the initial value and each following successor.
source code
Function Details [hide private]

concat(gens)

source code 

Returns a generator that is the concatenation
of the generators in the list.

EXAMPLES:
    sage: list(sage.combinat.generator.concat([[1,2,3],[4,5,6]]))
    [1, 2, 3, 4, 5, 6]

map(f, gen)

source code 

Returns a generator that returns f(g) for
g in gen.

EXAMPLES:
    sage: f = lambda x: x*2
    sage: list(sage.combinat.generator.map(f,[4,5,6]))
    [8, 10, 12]

element(element, n=1)

source code 

Returns a generator that yield a single element
n times.

EXAMPLES:
    sage: list(sage.combinat.generator.element(1))
    [1]
    sage: list(sage.combinat.generator.element(1, n=3))
    [1, 1, 1]

select(f, gen)

source code 

Returns a generator for all the elements g of gen
such that f(g) is True.

EXAMPLES:
    sage: f = lambda x: x % 2 == 0
    sage: list(sage.combinat.generator.select(f,range(7)))
    [0, 2, 4, 6]

successor(initial, succ)

source code 

Given an initial value and a successor function,
yeild the initial value and each following successor.
The generator will continue to generate values until
the successor function yields None.

EXAMPLES:
    sage: f = lambda x: x+1 if x < 10 else None
    sage: list(sage.combinat.generator.successor(0,f))
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]