module.fixed¶
Fixed storage capacity circular array.**
O(1) pops and pushes either end
O(1) indexing, does not support slicing
fixed total storage capacity
iterable, safely mutates while iterators iterating over previous state
comparisons compare identity before equality, like builtins
in boolean context, falsy when either empty or full, otherwise truthy
function
cafproduces fixed capacity circular array from arguments
- class pythonic_fp.circulararray.fixed.CAF¶
- __init__(*items: Iterable, cap: int = 2) None¶
- Parameters:
items – Optionally takes a single iterable to initially populate the circular array.
cap – Minimum fixed storage capacity of circular array.
- Raises:
TypeError – When
items[0]not iterable,ValueError – If more than 1 iterable is given.
- __repr__() str¶
Return repr(self).
- __str__() str¶
Return str(self).
- __eq__(other: object) bool¶
- Parameters:
other – The object to be compared to.
- Returns:
Trueif object is another CAF whose items compare as equal to the corresponding items in the CAF, otherwiseFalse.
- pushl(item: I) None¶
Push
itemon from left.- Parameters:
item – Single item pushed onto circular array from left (front).
- Raises:
ValueError – When called on a full
CAF.
- pushr(item: I) None¶
Push
itemon from Right.- Parameters:
item – Single
itempushed onto circular array from right (rear).- Raises:
ValueError – When called on a full fixed storage capacity circular array.
- popl() I¶
Pop single item off from left side.
- Returns:
Item popped from left side (front) of circular array.
- Raises:
ValueError – When called on an empty circular array.
- popr() I¶
Pop single item off from right side.
- Returns:
Item popped from right side (rear) of circular array.
- Raises:
ValueError – When called on an empty circular array.
- popld(default: I) I¶
Pop one item from left side of the circular array, provide a mandatory default value. “Safe” version of popl.
- Parameters:
default – Item returned if circular array is empty.
- Returns:
Item popped from left side or default item if empty.
- poprd(default: I) I¶
Pop one item from right side of the circular array, provide a mandatory default value. “Safe” version of popr.
- Parameters:
default – Item returned if circular array is empty.
- Returns:
Item popped from right side or default item if empty.
- poplt(maximum: int) tuple[I, ...]¶
Pop multiple items from left side of circular array.
- Parameters:
maximum – Maximum number of items to pop, may pop less if not enough items.
- Returns:
Tuple of items in the order popped, left to right.
- poprt(maximum: int) tuple[I, ...]¶
Pop multiple items from right side of circular array.
- Parameters:
maximum – Maximum number of items to pop, may pop less if not enough items.
- Returns:
Tuple of items in the order popped, right to left.
- rotl(n: int = 1) None¶
Rotate items to the left.
- Parameters:
n – Number of times to shift elements to the left.
- rotr(n: int = 1) None¶
Rotate items to the right.
- Parameters:
n – Number of times to shift elements to the right.
- map(f: Callable[[I], U]) CAF¶
Apply function
fover the circular array’s contents,- Parameters:
f – Callable from type
Ito typeU.- Returns:
New fixed capacity circular array instance.
- foldl(f: Callable[[I, I], I]) I¶
- foldl(f: Callable[[L, I], L], start: L) L
Fold left with a function and optional stating item.
- Parameters:
f – Folding function, first argument to
fis for the accumulator.start – Optional starting item.
- Returns:
Reduced value produced by the left fold.
- Raises:
ValueError – When circular array empty and no starting item given.
- foldr(f: Callable[[I, I], I]) I¶
- foldr(f: Callable[[I, R], R], start: R) R
Fold right with a function and an optional starting item.
- Parameters:
f – Folding function, second argument to
fis for the accumulator.start – Optional starting item.
- Returns:
Reduced value produced by the right fold.
- Raises:
ValueError – When circular array empty and no starting item given.
- capacity() int¶
Return fixed storage capacity of the circular array.
- Returns:
Fixed storage capacity.
- empty() None¶
Empty the circular array.
- fraction_filled() float¶
Find fraction of the storage capacity which is filled.
- Returns:
The ratio count/capacity.