iterables.drop_take¶
Drop and Take¶
module pythonic_fp.iterables.drop_take
Functions to drop or take values from an iterable.
- pythonic_fp.iterables.drop_take.drop(iterable: Iterable, n: int) Iterator¶
Drop the next n values from iterable.
- Parameters:
iterable – Iterable whose values are to be dropped.
n – Number of values to be dropped.
- Returns:
An iterator of the remaining values.
- pythonic_fp.iterables.drop_take.drop_while(iterable: Iterable, pred: Callable[[D], bool]) Iterator¶
Drop initial values from iterable while predicate is true.
- Parameters:
iterable – Iterable whose values are to be dropped.
pred – Single argument Boolean valued function, the “predicate”.
- Returns:
An iterator beginning where pred returned false.
- pythonic_fp.iterables.drop_take.take(iterable: Iterable, n: int) Iterator¶
Return an iterator of up to n initial values of an iterable.
- Parameters:
Iterable – iterable providing the values to be taken.
n – Number of values to be dropped.
- Returns:
An iterator of up to n initial values from iterable.
- pythonic_fp.iterables.drop_take.take_while(iterable: Iterable, pred: Callable[[D], bool]) Iterator¶
Yield values from iterable while predicate is true.
Warning
Risk of value loss if iterable is multiple referenced iterator.
- Parameters:
iterable – Iterable providing the values to be taken.
pred – Single argument Boolean valued function, the “predicate”.
- Returns:
An Iterator of of values from iterable until predicate false.
- pythonic_fp.iterables.drop_take.take_split(iterable: Iterable, n: int) tuple[Iterator, Iterator]¶
Same as take except also return iterator of remaining values.
Warning
CONTRACT: Do not access the second returned iterator until the first one is exhausted.
- Parameters:
iterable – Iterable providing the values to be taken.
n – maximum Number of values to be taken.
- Returns:
An iterator of values taken and an iterator of remaining values.
- pythonic_fp.iterables.drop_take.take_while_split(iterable: Iterable, pred: Callable[[D], bool]) tuple[Iterator, Iterator]¶
Yield values from iterable while predicate is true.
Warning
CONTRACT: Do not access the second returned iterator until the first one is exhausted.
- Parameters:
iterable – Iterable providing the values to be taken.
pred – Single argument Boolean valued function.
- Returns:
Tuple of iterator of values taken and an iterator of remaining values.