module immutable_list¶
- class pythonic_fp.containers.immutable_list.IList¶
Bases:
Hashable,Genericimmutable 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
intmultiplication supportedaddition is concatenation resulting in a union type
- __init__(*ds: Iterable) None¶
init
- param ds:
One optional iterable.
- __hash__() int¶
hash
Hashability enforced at runtime by initializer.
- returns:
Hash value.
- __iter__() Iterator¶
iterate
Forward iterate, left to right.
- yields:
The contained values.
- __reversed__() Iterator¶
iterate
Reverse iterate, left to right.
- yields:
The contained values in reverse order.
- __bool__() bool¶
bool
- returns:
Trueif not empty,Falseif empty.
- __len__() int¶
len
- returns:
The number of items in the
Ilist.
- __eq__(other: object, /) bool¶
Return self==value.
- __getitem__(idx: int, /) D¶
- __getitem__(idx: slice, /) IList[D]
getitem
Indexable and sliceable but otherwise immutable.
- param idx:
Either a
sliceor andindex.- returns:
A slice or the value.
- __repr__() str¶
repr string
- returns:
A string to reproduce the value.
- __str__() str¶
user string
- returns:
A string meaningful to an end user.
- foldl(f: Callable[[L, D], L], /, start: L | None = None, default: L | None = None) L | None¶
fold left
- param f:
Folding function, first argument is for the accumulated value.
- param start:
Optional starting value.
- param default:
Optional default value if fold does not exist.
- returns:
Left folded value.
- raises ValueError:
When empty and neither a start value or default value not given.
- foldr(f: Callable[[D, R], R], /, start: R | None = None, default: R | None = None) R | None¶
fold right
- param f:
Folding function, second argument is for the accumulated value.
- param start:
Optional starting value.
- param default:
Optional default value if fold does not exist.
- returns:
Right folded value.
- raises ValueError:
When empty and neither a start value or default value not given.
- __add__(other: IList[D], /) IList[D]¶
add by concatenation
- param other:
The
othersame typedIList.- returns:
New
IListinstance with concatenated values.- raises ValueError:
When
otheris not anIList.
TODO
Return
NotImplementedif appropriate?
- __mul__(num: int, /) IList[D]¶
add by concatenation
- param other:
The
othersame typedIList.- returns:
New
IListinstance with concatenated values.- raises ValueError:
When
otheris not anIList.
TODO
Consider returning
NotImplementedif appropriate? Maybe define a “column vector” version?
- __rmul__(num: int, /) IList[D]¶
concatenation with itself
- param num:
Number of times to concatenate
IListwith itself.- returns:
A new
IListinstance with concatenated values.- raises ValueError:
When
otheris not anIList.
- 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.- param f:
Folding function used to produce partial folds.
- param s:
Optional starting value.
- returns:
New
IListof the partial folds.
- map(f: Callable[[D], U], /) IList¶
map
- parameter f:
Function to map over the
IList.- returns:
A new
IListinstance with the mapped values.
- bind(f: Callable[[D], IList[U]], merge_enum: MergeEnum = MergeEnum.Concat, yield_partials: bool = False) IList[U] | Never¶
bind
- param f:
Function
D -> IList[U]to bind with different merge strategies.- param merge_type:
MergeEnumto determine how to merge the result.- param yield_partials:
Yield unmatched values if
MergeEnumgiven as merge type.- return:
New
IListinstance.- raises ValueError:
If given an unknown merge enumeration.