module functional_tuple

class pythonic_fp.containers.functional_tuple.FTuple

Bases: tuple[D, …], Generic

Functional Tuple

  • intended for further inheritance

  • supports both indexing and slicing

  • int multiplication and FTuple addition supported

  • addition concatenates results, resulting in a Union type

  • both left and right int multiplication supported

  • homogeneous in its data type

  • unslotted

Note

Example of code very early in project. Different ways to use __dunders__ than what I do lately.

__reversed__() Iterator

reverse iter

yields:

the tuples elements in reverse order

__eq__(other: object, /) bool

equality comparison

param other:

The object to which to be compared.

returns:

True if other is the same type and corresponding elements compare as equal.

__getitem__(idx: SupportsIndex) D
__getitem__(idx: slice) tuple[D, ...]

Return self[key].

__repr__() str

Return repr(self).

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

fold left

Reduce left with optional starting and default values.

param f:

The folding function, first argument is for the accumulated value.

param start:

An optional starting value.

param default:

An optional default value if fold does not exist.

raises ValueError:

When FTuple empty and a start value was not not given.

returns:

Folded value if it exists, otherwise the default value if given.

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

fold right

Reduce right with optional starting and default values.

param f:

The folding function, second argument is for the accumulated value.

param start:

An optional starting value.

param default:

An optional default value if fold does not exist.

raises ValueError:

when FTuple empty and a start value was not given

returns:

The folded value if it exists, otherwise the default value if given.

copy() FTuple[D]

copy

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

returns:

A new FTuple instance.

__add__(other: object, /) tuple[D, ...]

Return self+value.

__mul__(num: SupportsIndex) tuple[D, ...]

Return self*value.

__rmul__(num: SupportsIndex) tuple[D, ...]

Return value*self.

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

accumulate partial folds

param f:

Folding function used to produce partial folds.

param s:

Optional starting value.

returns:

New FTuple of the partial folds.

map(f: Callable[[D], U], /) FTuple

map

param f:

Folding function used to produce partial folds.

returns:

A new FTuple instance.

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

bind

Flat map function f with the FTuple with different merging strategies.

param f:

Function D -> FTuple[U]

param merge_type:

MergeEnum to determine how to merge the result.

param yield_partials:

Yield unmatched values if MergeEnum given as merge type.

returns:

A new FTuple instance.

raises ValueError:

If given an unknown merge enumeration.