module immutable_list

Pythonic FP - Immutable guaranteed hashable lists.

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

Immutable List like data structure.

  • hashability should be enforced by LSP tooling

  • hashability will be enforced at runtime

  • its method type parameters are also covariant

  • supports both indexing and slicing

  • addition and left & right int multiplication supported

    • addition is concatenation resulting in a union type

Parameters:

dss – 0 or 1 iterables

__init__(*dss: Iterable) None
Parameters:

dss – 0 or 1 iterables

__hash__() int

Return hash(self).

__repr__() str

Return repr(self).

__str__() str

Return str(self).

__eq__(other: object, /) bool

Return self==value.

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

Fold Left.

Parameters:
  • f – Folding function, first argument is for the accumulated value.

  • start – Optional starting value.

  • default – Optional default value if fold does not exist.

Returns:

Folded 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.

Parameters:
  • f – Folding function, second argument is for the accumulated value.

  • start – Optional starting value.

  • default – Optional default value if fold does not exist.

Returns:

Folded value.

Raises:

ValueError – When empty and a start value not given.

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

Accumulate partial folds.

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

Parameters:
  • f – Folding function used to produce partial folds.

  • s – Optional starting value.

Returns:

New FTuple of the partial folds.

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

Bind function f to the IList.

Parameters:
  • f – Function D -> IList[U]

  • merge_typeMergeEnum to determine how to merge the result.

  • yield_partials – Yield unmatched values if MergeEnum given as merge type.

Returns:

Resulting IList.

Raises:

ValueError – If given an unknown merge enumeration.