tools2374%python.module
fault.context

Function and iterator tools used by local projects.

functools
import

itertools0
import

typing0
import

dataclasses0
import

cachedcalls0
data

cachedcalls = functools.lru_cache

partial0
data

partial = functools.partial

nothing20%
function
None

nothing(*args, **kw)

Callable that returns None regardless of the arguments and keywords given.

reflect0
function

reflect(obj)

Callable that returns the single argument that it was given.

constant40%
function

constant(obj)

Return a callable that returns the given object regardless of the given parameters.

unique0
function

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

iterable

The iterable whose duplicate items should be eliminated.

existing

The initial items in the filter set. Arguments given as existing will never be emitted. For instance, filtering None may be common.

set

Undocumented.

interlace0
function

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%
function

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%
function

plural(f)

Create a function that pluralizes the return of the given callable, f.

unroll0
function

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
data

sum_lengths = compose(sum, partial(map, len))

group100%
function

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

condition

The grouping item in the tuple is the item that triggers a True result from condition.

iterable

The sequence item in the tuple is a sequence of items where the result of the condition was False.

initial

Designate the initial grouping to be emitted. Defaults to None.

Sequence

Undocumented.

cachedproperty0
class

Attribute override for immutable property methods.

Presumes the wrapped method name is consistent with the property name.

cachedproperty__init__0
method

__init__(self, method)

cachedproperty__get__175%
method

__get__(self, instance, Class)

consistency0
function
int

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.