caldera.utils.functional

functional.py.

Functional programming methods.

Generally, functions are named by verb-noun-qualifier

verbs

ignore - returned function ignores certain elements of the iterator, returning an iterator of the remaining elements. return - returns the result of the function, rather than another iterator. group - returned function returns an iterator of groups (i.e. iterables of each element T, such as List[T]), instead of map - applies a new function to elements of the iterator

nouns

each - returned function applies to each element in the iterator all - returned function applies to the entire iterator, rather than to each element

qualifier

until - iterates until some condition is met

Special Methods (i.e. piping methods)

compose

Functions

apply(func)

apply_each(func)

cat(*arrs)

chain_each()

rtype

Callable[[Generator[Generator[~T, None, None], None, None]], Generator[~T, None, None]]

compose(*funcs)

Create a function composition.

consume(f)

Applies a function to the iterator and then consumes.

count_each()

counter([i])

param i

empty_generator(*_)

enumerate_each(*[, reverse])

Non-tee version of enumerate.

filter_each(f[, inverse])

param f

get_each(i[, default])

param i

get_from(d[, default])

param d

getattr_each(k)

param k

group_each_by_key(f[, value_func])

param f

group_each_consecutive(condition)

param condition

group_each_into_chunks(chunk_size)

Returns a new function the groups iterables by chunks of the specified size.

group_each_until(condition[, group_if, …])

param condition

ignore_each_count([n])

pipe( fn_side_effect(fn_next(n)) )

ignore_each_until(f)

param f

index_each(i)

param i

index_from(d)

param d

iter_count([n])

param n

iter_each_unique()

iter_each_until(f)

param f

iter_next()

iter_reverse()

iter_step([step_size])

param step_size

map_all(f, *args, **kwargs)

Apply the function to the iterator itself.

map_all_if(condition, if_func[, else_func])

map_each(f, *args, **kwargs)

param f

pairwise_each()

rtype

Callable[[Generator[~T, None, None]], Generator[Tuple[~T, ~T], None, None]]

reduce_all(f)

reduce_each(f)

repeat_all(n)

param n

reverse_each()

shuffle_each()

star(f)

Return a function equivalent to lambda args: f(*args)

tee_all([n])

param n

tee_consume(*funcs)

tee_pipe(*funcs)

Tee the iterator and apply a new series of functions without affecting the primary iterator.

tee_pipe_yield(*funcs)

trycatch(*exceptions[, catch_yields])

Catches the provided exceptions.

until(f[, inverse, yield_last])

param f

yield_all(*funcs)

param funcs

zip_all([reverse])

param reverse

zip_each_with(*arrs[, first])

zipmap_each_with(*funcs[, first])

param first