-
Piotr Maślanka authoredfcb7dfa4
sequences
choose
To return the single element that returns true on given callable, use the following function:
take_n
For the rare moments, when you wish you could just do:
iterator: tp.Iterator[T] = iterator
n_elements: tp.List[T] = iterator[:n]
But it doesn't let you do this, because iterator is not subscriptable. However, this function comes to the rescue:
is_instance
A factory for filter functions that check if given object is an instance of something (or multiple classes, if passed a tuple of classes). Use like that
orders: tp.List[BaseOrder] = ...
read_orders = filter(is_instance(ReadOrder), orders)
is_last
add_next
Sometimes you need to iterate through list and take also the next element.
half_cartesian
Sometimes you need just a half of your Cartesian product, for example for operations that are commutative (eg. checking for collisions, if object A collides with B then B collides with A).
It helps you save time during computationally intensive operations.
This routine will return a iterator of tuple containing two elements from the same set (ie. it will do something like a cartesian power of two).
skip_first
zip_shifted
This is deprecated. Use zip(shift(...))
instead.