containers.immutable_list

Immutable List

Pythonic FP - Immutable guaranteed hashable lists

  • hashable if elements are hashable

  • declared covariant in its generic datatype - hashability should be enforced by LSP tooling - hashability will be enforced at runtime - IList addition supported via concatenation - IList integer multiplication supported

class pythonic_fp.containers.immutable_list.IList(*dss: Iterable[D])

Immutable List like data structure.

  • its method type parameters are also covariant

  • hashability will be enforced by LSP tooling

  • supports both indexing and slicing

  • addition concatenates results, resulting type a Union type

  • both left and right int multiplication supported

accummulate(f: Callable[[L, D], L], s: L | None = None, /) IList

Accumulate partial folds

Accumulate partial fold results in an IList with an optional starting value.

bind(f: Callable[[D], IList], merge_enum: MergeEnum = MergeEnum.Concat, yield_partials: bool = False) IList | Never

Bind function f to the IList.

Parameters:

ds – values to instantiate IList

Returns:

resulting IList

Raises:

ValueError – if given unknown merge_type

foldl(f: Callable[[L, D], L], /, start: L | None = None, default: L | None = None) L | None

Fold Left

  • fold left with an optional starting value

  • first argument of function f is for the accumulated value

“raises ValueError: when empty and a start value not given

foldr(f: Callable[[D, R], R], /, start: R | None = None, default: R | None = None) R | None

Fold Right

  • fold right with an optional starting value

  • second argument of function f is for the accumulated value

“raises ValueError: when empty and a start value not given