drop and take¶
Drop and Take
Functions which drop or take items from an iterable.
Important
If iterable is a multiply referenced iterator, items dropped or taken need not be the next consecutive items.
Important
If iterable is mutable, iterator may be affected by the current state of the original iterable.
Tip
Prefer immutable iterables over mutable ones.
- pythonic_fp.iterables.drop_take.drop(iterable: Iterable, n: int) Iterator¶
drop
Drop the next n items from iterable.
- param iterable:
Iterable whose items are to be dropped.
- param n:
Number of items to be dropped.
- yields:
The remaining items.
- pythonic_fp.iterables.drop_take.drop_while(iterable: Iterable, pred: Callable[[D], bool]) Iterator¶
drop while
Drop initial items from iterable while predicate is true.
- param iterable:
Iterable whose items are to be dropped.
- param pred:
Single argument Boolean valued function.
- yields:
items starting when
predreturnsFalse.
- pythonic_fp.iterables.drop_take.take(iterable: Iterable, n: int) Iterator¶
take
Return an iterator yielding up to n items from an iterable.
- param Iterable:
Iterable providing the items to be taken.
- param n:
Number of items to be taken.
- yields:
Up to n items from iterable.
- pythonic_fp.iterables.drop_take.take_while(iterable: Iterable, pred: Callable[[D], bool]) Iterator¶
take while
Return an iterator of items until predicate false.
- param iterable:
Iterable providing the items to be taken.
- param pred:
Single argument Boolean valued function.
- yields:
Items from iterable while predicate is true.
Warning
Risk of data loss if iterable is multiple referenced iterator.
- pythonic_fp.iterables.drop_take.take_split(iterable: Iterable, n: int) tuple[Iterator, Iterator]¶
take split
Same as take except also return an iterator of the remaining items.
CONTRACT
IMPORTANT: Do not access the second iterator until the first one is completely exhausted.
- param iterable:
Iterable providing the items to be taken.
- param n:
maximum Number of items to be taken.
- returns:
A tuple containing an iterator of items taken and an iterator of remaining items.
- pythonic_fp.iterables.drop_take.take_while_split(iterable: Iterable, pred: Callable[[D], bool]) tuple[Iterator, Iterator]¶
take while
Same as take_while except also return an iterator of the remaining items.
CONTRACT
IMPORTANT: Do not access the second iterator until the first one is completely exhausted.
- param iterable:
Iterable providing the items to be taken.
- param pred:
Single argument Boolean valued function.
- returns:
A tuple containing an iterator of items taken while
predtruthy and an iterator of remaining items.