Skip to content

functional

Module for functional programming utilities.

Functions:

Name Description
apply_in_parallel

Apply a function to multiple items' values, one worker thread per item.

sequential

Compose functions sequentially.

apply_in_parallel

apply_in_parallel(
    func: Callable[..., R],
    items: Mapping[K, V],
    *extra_args: object,
    max_workers: int,
) -> dict[K, R]

Apply a function to multiple items' values, one worker thread per item.

Parameters:

Name Type Description Default

func

Callable[..., R]

A function taking one item's value (plus any extra_args) and returning a result.

required

items

Mapping[K, V]

A mapping of key to value to pass to func.

required

*extra_args

object

Additional positional arguments passed to every func call, after the value.

required

max_workers

int

The upper bound on worker threads to use, further capped by len(items).

required

Returns:

Type Description
dict[K, R]

A mapping of key to func's output, with the same keys as items.

sequential

sequential(
    *functions: Callable[..., Any],
) -> Callable[..., Any]
sequential(
    *functions: Callable[..., Any],
) -> Callable[..., Any]
sequential(
    *functions: Callable[..., Any],
) -> Callable[..., Any]

Compose functions sequentially.

Parameters:

Name Type Description Default

functions

Callable[..., Any]

The functions to compose. The first function may take any arguments, but the rest must take the output of the previous function.

required

Raises:

Type Description
ValueError

If no functions are passed.

Returns:

Type Description
Callable[..., Any]

A function that composes the given functions.