Function and iterator tools used by local projects.
functools
itertools0
typing0
dataclasses0
cachedcalls0
cachedcalls = functools.lru_cache
partial0
partial = functools.partial
nothing20%None
nothing(*args, **kw)
Callable that returns None regardless of the arguments and keywords given.
reflect0
reflect(obj)
Callable that returns the single argument that it was given.
constant40%
constant(obj)
Return a callable that returns the given object regardless of the given parameters.
unique0
unique(iterable, *existing)
Iterate through the contents of the iterable, but only allow an item to be emitted once.
| WARNING | |
The implementation uses a set to track which items have transpired. It is never reset internally, so the generator can allocate arbitrary quantities of memory. |
uniqueParameters
interlace0
interlace(*iters)
An iterator constructor that takes a sequence of iterables and interlaces their items one after another. While uncommon, the pattern produced by interlace is complicated enough that forcing its recreation is undesirable.
Interlace produces an iterator following the pattern:
interlace(i1, i2, ..., in) -> (
i1-0, i2-0, ..., in-0,
i1-1, i2-1, ..., in-1,
⋮
i1-n, i2-n, ..., in-n,
)
compose290%
compose(*callables)
Return a composition of the given callable arguments.
Executing a composition is equivalent to: g(f(x)) where g and f are the parameters to compose: compose(g,f)(x).
Compose has some trivial intelligence in that compositions of single functions return the function and compositions of no functions returns reflect.
The resulting composition exposes the callables on the function's "callables" attribute.
plural20%
plural(f)
Create a function that pluralizes the return of the given callable, f.
unroll0
unroll(f)
Given a callable taking a single parameter, create another that maps the callable against a sequence.
Equivalence:
unroll(f)(iterable) == [f(x) for x in iterable]
sum_lengths0
sum_lengths = compose(sum, partial(map, len))
group100%
group(condition, iterable, initial)
Structure the given iterable by the given condition. Returns a generator producing (grouping, sequence) pairs.
A True result from condition essentially terminates the subsequence, and creates a new sequence to be populated while condition is False.
groupParameters
cachedproperty0
Attribute override for immutable property methods.
Presumes the wrapped method name is consistent with the property name.
cachedproperty__init__0
__init__(self, method)
cachedproperty__get__175%
__get__(self, instance, Class)
consistency0int
consistency(*iterables)
Return the level of consistency among the elements produced by the given iterables. The counting stops when an element is not equal to the others at the same index.
More commonly, the common prefix depth or length of all the given iterables. Elements must be hashable; equality is indirectly performed by forming a set.