Singly Linked Stream

class streams.SinglyLinkedStream(value, next_thunk, *, does_memoize=True)[source]

Bases: streams.abc.LinearStream[streams.VT]

A singly linked list class implemented as a stream.

Parameters
  • value (VT) –

  • next_thunk (Callable[[], Optional[SinglyLinkedStream[VT]]]) –

  • does_memoize (bool) –

Return type

None

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

Optional[SinglyLinkedStream[VT]]

classmethod from_iterable(iterable, does_memoize=True)

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]]

classmethod map(fn, *streams, does_memoize=True)[source]

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.MT]) – the function to be applied to each value in the stream

  • streams (streams.SinglyLinkedStream) – 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.SinglyLinkedStream[streams.MT]

property next: Optional[streams.SinglyLinkedStream[streams.VT]]

Returns the next node.

property value: streams.VT

Returns the value of the node.