Tutorial: choose a collection#
Expression has a lazy sequence type and immutable collections. Use them when their behaviour is part of the contract; otherwise, ordinary Python collections are a good default.
Seq is useful when a value flows through several iterable transformations. It does not
materialize its values until a consumer asks for them.
from expression.collections import Block, Map, Seq
source = Seq.of(1, 2, 3, 4, 5)
even_squares = source.filter(lambda value: value % 2 == 0).map(lambda value: value**2)
assert list(even_squares) == [4, 16]