Linear Stream

class streams.abc.LinearStream[source]

Bases: streams.abc.Stream[streams.abc.VT], collections.abc.Iterable[streams.abc.VT]

An abstract linearly linked list class implemented as a stream class.

abstract filter(predicate=None)[source]

Returns a new stream that filters out the values that do not satisfy the predicate.

Parameters

predicate (Callable[[VT], bool]) – the function to apply to the values in the stream. It defaults to testing each value itself for validity.

Return type

LinearStream[VT]

classmethod from_iterable(iterable, does_memoize=True)[source]

Returns a new stream that contains data from an iterable. Use of the iterable elsewhere afterward is generally inadvisable Otherwise, the stream might become out of sync.

Parameters
  • iterable (collections.abc.Iterable[streams.abc.VT]) – the iterable from which to create the stream

  • does_memoize (bool) – By default, the node will cache the result of next_thunk. This can potentially hog a lot of memory. To turn caching off, set does_memoize to False. It might be desirable to propagate this to composite streams generated by custom functions.

Return type

Optional[streams.abc.LinearStream[streams.abc.VT]]

abstract classmethod map(fn, *streams, does_memoize=True)

Returns a new stream that contains the return values of the function applied to each item in the streams.

Parameters
  • fn (collections.abc.Callable[..., streams.abc.MT]) – the function to be applied to each value in the stream

  • streams (streams.abc.Stream) – the tuple of streams that contain the values to be mapped

  • does_memoize (bool) – By default, the node will cache the result of next_thunk. This can potentially hog a lot of memory. To turn caching off, set does_memoize to False. It might be desirable to propagate this to composite streams generated by custom functions.

Return type

streams.abc.Stream[streams.abc.MT]

abstract property next: Optional[streams.abc.LinearStream[streams.abc.VT]]

Returns the next node.

abstract property value: streams.abc.VT

Returns the value of the node.