hydra.overlay.python.lib.lists module

Python implementations of hydra.overlay.python.lib.lists primitives.

Inputs accept any Sequence; outputs are ConsList instances (returned as Sequence[A]). ConsList is a structurally-shared persistent list, so chained primitives — typical of inference-style workloads — avoid the O(n) full-tuple-copy that tuple-based implementations would impose.

hydra.overlay.python.lib.lists.apply(fs: Sequence[Callable[[A], B]], values: Sequence[A]) Sequence[B]

Apply a list of functions to a list of values (applicative style).

hydra.overlay.python.lib.lists.at(i: int, values: Sequence[A]) object

Get the element at a specified index, returning none if out of bounds.

hydra.overlay.python.lib.lists.bind(values: Sequence[A], f: Callable[[A], Sequence[B]]) Sequence[B]

Apply a function that returns lists to each element and flatten results.

hydra.overlay.python.lib.lists.concat(values: Sequence[Sequence[A]]) Sequence[A]

Concatenate a list of lists.

hydra.overlay.python.lib.lists.concat2(values1: Sequence[A], values2: Sequence[A]) Sequence[A]

Concatenate two lists.

hydra.overlay.python.lib.lists.cons(value: A, values: Sequence[A]) Sequence[A]

Prepend a value to a list. O(1) when values is already a ConsList.

hydra.overlay.python.lib.lists.distinct(values: Sequence[A]) Sequence[A]

Remove duplicate elements from a list.

hydra.overlay.python.lib.lists.drop(n: int, values: Sequence[A]) Sequence[A]

Drop the first n elements from a list.

If n <= 0, returns the full list (Haskell semantics).

hydra.overlay.python.lib.lists.drop_while(predicate: Callable[[A], bool], values: Sequence[A]) Sequence[A]

Drop elements from the beginning of a list while predicate is true.

hydra.overlay.python.lib.lists.filter(f: Callable[[A], bool], values: Sequence[A]) Sequence[A]

Filter a list based on a predicate.

hydra.overlay.python.lib.lists.find(predicate: Callable[[A], bool], values: Sequence[A]) object

Find the first element matching a predicate.

hydra.overlay.python.lib.lists.foldl(f: Callable[[B, A], B], initial: B, values: Sequence[A]) B

Fold a list from the left.

hydra.overlay.python.lib.lists.foldr(f: Callable[[A, B], B], initial: B, values: Sequence[A]) B

Fold a list from the right.

hydra.overlay.python.lib.lists.group(values: Sequence[A]) Sequence[Sequence[A]]

Group consecutive equal elements.

hydra.overlay.python.lib.lists.head(values: Sequence[A]) object

Get the first element of a list, returning none if the list is empty.

hydra.overlay.python.lib.lists.init(values: Sequence[A]) object

Return all elements except the last, returning none if empty.

hydra.overlay.python.lib.lists.intersperse(separator: A, values: Sequence[A]) Sequence[A]

Intersperse a value between elements of a list.

hydra.overlay.python.lib.lists.is_empty(values: Sequence[Any]) bool

Check if a list is empty.

hydra.overlay.python.lib.lists.join(separator: Sequence[A], values: Sequence[Sequence[A]]) Sequence[A]

Intercalate a list of lists with a separator list between each.

Returns empty list if values is empty (Haskell semantics).

hydra.overlay.python.lib.lists.last(values: Sequence[A]) object

Get the last element of a list, returning none if the list is empty.

hydra.overlay.python.lib.lists.length(values: Sequence[Any]) int

Get the length of a list.

hydra.overlay.python.lib.lists.map(f: Callable[[A], B], values: Sequence[A]) Sequence[B]

Map a function over a list.

hydra.overlay.python.lib.lists.member(value: A, values: Sequence[A]) bool

Check if an element is in a list.

hydra.overlay.python.lib.lists.partition(predicate: Callable[[A], bool], values: Sequence[A]) tuple[Sequence[A], Sequence[A]]

Partition a list into elements that satisfy a predicate and elements that do not.

hydra.overlay.python.lib.lists.replicate(n: int, value: A) Sequence[A]

Create a list with n copies of a value.

hydra.overlay.python.lib.lists.reverse(values: Sequence[A]) Sequence[A]

Reverse a list.

hydra.overlay.python.lib.lists.singleton(value: A) Sequence[A]

Create a single-element list.

hydra.overlay.python.lib.lists.sort(values: Sequence[A]) Sequence[A]

Sort a list.

hydra.overlay.python.lib.lists.sort_by(key: Callable[[A], B], values: Sequence[A]) Sequence[A]

Sort a list based on a key function.

hydra.overlay.python.lib.lists.span(predicate: Callable[[A], bool], values: Sequence[A]) tuple[Sequence[A], Sequence[A]]

Split a list at the first element where predicate fails.

hydra.overlay.python.lib.lists.tail(values: Sequence[A]) object

Get all elements except the first, returning none if empty.

hydra.overlay.python.lib.lists.take(n: int, values: Sequence[A]) Sequence[A]

Take the first n elements from a list.

If n <= 0, returns an empty list (Haskell semantics).

hydra.overlay.python.lib.lists.transpose(values: Sequence[Sequence[A]]) Sequence[Sequence[A]]

Transpose a list of lists.

hydra.overlay.python.lib.lists.uncons(values: Sequence[A]) object

Split a list into its head and tail, returning none if empty.

hydra.overlay.python.lib.lists.zip(values1: Sequence[A], values2: Sequence[B]) Sequence[tuple[A, B]]

Zip two lists into pairs.

hydra.overlay.python.lib.lists.zip_with(f: Callable[[A, B], C], values1: Sequence[A], values2: Sequence[B]) Sequence[C]

Zip two lists with a combining function.