containers.functional_tuple

Functional Tuple

Pythonic FP - Functional Tuple

class pythonic_fp.containers.functional_tuple.FTuple(iterable=(), /)

Functional Tuple suitable for inheritance

  • Supports both indexing and slicing

  • FTuple addition and int multiplication supported

    • addition concatenates results, resulting in a Union type

    • both left and right int multiplication supported

    • homogeneous in its data type

    • supports being further inherited from

    • unslotted

  • Since these tuples are homogeneous, their covariance may be quirky

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

Accumulate partial folds

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

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

Bind function f to the FTuple.

Parameters:

ds – values to instantiate FTuple

Returns:

resulting FTuple

Raises:

ValueError – if given unknown merge_type

copy() FTuple[D]

Return a shallow copy of FTuple in O(1) time & space complexity.

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 FTuple 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 FTuple empty and a start value not given