Chain

Contents
  • Variadic vs infix
  • Infinity
  • chain.from_iterable

To concatenate two Python iterators, we use chain.itertools.chain

>>> it = chain([1,2], [3,4])

The resulting iterator consists of each element from the first argument (1 and 2), followed by each element of the second argument (3 and 4).

>>> list(it)
[1, 2, 3, 4]

The corresponding Haskell function(++) in Data.List and Prelude. is called (++).Equivalently, (++) may be replaced with the more general operator (<>), because conatenation is the semigroup operation for the list type.

λ> [1, 2] ++ [3, 4]
[1,2,3,4]

Sign up for access to the full page, plus the complete archive and all the latest content.