Doubly Linked Stream¶
- class streams.DoublyLinkedStream(value, next_thunk, previous_thunk=None, *, does_memoize=True)[source]¶
Bases:
streams.SinglyLinkedStream[streams.VT],collections.abc.Reversible[streams.VT]A doubly linked list class implemented as a stream.
- Parameters
value (VT) –
next_thunk (Callable[[], Optional[DoublyLinkedStream[VT]]]) –
previous_thunk (Callable[[], Optional[DoublyLinkedStream[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[DoublyLinkedStream[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, setdoes_memoizetoFalse. 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.DoublyLinkedStream) – 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, setdoes_memoizetoFalse. It might be desirable to propagate this to composite streams generated by custom functions.
- Return type
streams.DoublyLinkedStream[streams.MT]
- property next: Optional[streams.DoublyLinkedStream[streams.VT]]¶
Returns the next node.
- property previous: Optional[streams.DoublyLinkedStream[streams.VT]]¶
Returns the previous node.
- property value: streams.VT¶
Returns the value of the node.