Skip to content

Stream API

fpstreams.Stream

Bases: BaseStream[T]

__init__(iterable, size_hint=None)

Parameters:

Name Type Description Default
iterable Iterable[T]

The data source.

required
size_hint Optional[int]

Known size of the stream. If None, we calculate it if possible.

None

__iter__()

Allows the stream to be used in standard for-loops.

of(*elements) staticmethod

Creates a stream from a sequence of values. Usage: Stream.of(1, 2, 3, 4)

generate(supplier) staticmethod

Creates an infinite stream by calling supplier() repeatedly.

iterate(seed, unary_op) staticmethod

Creates an infinite stream: seed, f(seed), f(f(seed))...

limit(max_size)

Optimized limit. Uses slicing if source is a list/tuple/range.

skip(n)

Optimized skip. Uses slicing if source is a list/tuple/range.

batch(size)

Chunks the stream into lists of size N.

window(size, step=1)

Creates a sliding window over the stream.

scan(identity, accumulator)

Performs a cumulative reduction.

zip_longest(other, fillvalue=None)

Zips with another iterable, filling missing values instead of stopping.

to_async()

Converts this synchronous stream into an AsyncStream. Useful for switching from processing in memory to sending data over network.