module functional_tuple¶
- class pythonic_fp.containers.functional_tuple.FTuple¶
Bases:
tuple[D, …],GenericFunctional 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
objectto which to be compared.- returns:
Trueifotheris 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
FTupleempty 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
FTupleempty 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
FTuplein O(1) time & space complexity.- returns:
A new
FTupleinstance.
- __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
FTupleof the partial folds.
- map(f: Callable[[D], U], /) FTuple¶
map
- param f:
Folding function used to produce partial folds.
- returns:
A new
FTupleinstance.
- bind(f: Callable[[D], FTuple[U]], merge_type: MergeEnum = MergeEnum.Concat, yield_partials: bool = False) FTuple[U] | Never¶
bind
Flat map function
fwith theFTuplewith different merging strategies.- param f:
Function
D -> FTuple[U]- param merge_type:
MergeEnumto determine how to merge the result.- param yield_partials:
Yield unmatched values if
MergeEnumgiven as merge type.- returns:
A new
FTupleinstance.- raises ValueError:
If given an unknown merge enumeration.