Algorithms

Table of contents

  1. Module itertools — functions that create iterators
  2. Module functional — functional programming

Module itertools

Functions that create iterators.

chain(*iterables)
Lazy evaluation of iter(iterables.sum(list)).
> chain(1..2,1..4).list()
[1, 2, 1, 2, 3, 4]
permutations(a)
Return an iterator over all permutations of a.
repeat(x), repeat(x,n)
Return an iterator that returns x over and over again. If n is given, the iterator will be exhausted after n calls.

Module functional

Functional programming.

fix(F)
Memoizing fixed point combinator.
fib = fix(|f,n| 1 if n==1 or n==2 else f(n-1)+f(n-2))
lazy(|| expression)
Create a new lazily evaluated expression. Evaluation of a such an expression x is done by x.value(). The expression is evaluated only once, the result then memoized for subsequent calls.
Lazy
Data type of lazily evaluated expressions.