pathex.adts.util module
Useful functions and constants
- Module
pathex.adts.util
This module contains some useful little functions and constants.
Caution
The content of this module is not intended to be part of the exposed main features of PathEx, so it may change in the future. It is documented here only because it is part of the current internal design of the library.
- SET_OF_STRS
alias of
types.SetWrapper
- SET_OF_TUPLES
alias of
types.SetWrapper
- get_head_tail(iterable: Iterable[T]) tuple[object, Iterator[T] | None] [source]
Decompose the given
iterable
into its head and tail.Example:
>>> head, tail = get_head_tail([1, 2, 3, 4]) >>> assert head == 1 >>> assert list(tail) == [2, 3, 4]
>>> assert (None, None) == get_head_tail(()) >>> head, tail = get_head_tail(iter([1, 2, 3, 4])) >>> assert head == 1 >>> assert list(tail) == [2, 3, 4]
- take(n: int, iterable: Iterable[T]) Iterator[T] [source]
Returns an iterator that takes
n
elements fromiterable
.If
iterable
has less thann
elements, all elements fromiterable
are given.Example:
>>> assert list(take(5, range(7))) == [0, 1, 2, 3, 4] >>> assert list(take(5, range(4))) == [0, 1, 2, 3]
- Parameters
n (int) – the amount of elements to be taken.
it (Iterable[T]) – the iterable to be taken from.
- Returns
The resulting iterator.
- Return type
Iterator[T]