lifo¶
- class pythonic_fp.queues.lifo.LIFOQueue¶
Bases:
GenericLIFOQueue
Stateful Last-In-First-Out (LIFO) Queue data structure.
O(1) pops
O(1) amortized pushes
O(1) length determination
in a Boolean context, true if not empty, false if empty
will automatically increase storage capacity when needed
neither indexable nor sliceable by design
- __init__(*ds: Iterable) None¶
Initializer
Initialize
LIFOQueuewith 0 or 1 iterables to populate the queue in natural LIFO order.- Parameters:
ds – Takes 0 or 1 iterable parameters.
- Raises:
ValueError – When more than one parameter is provided.
TypeError – When passed a non-iterable parameter.
- __bool__() bool¶
Truthiness
LIFOQueuetruthy when non-empty, falsy when empty.
- __len__() int¶
Get length
Return the number of data elements in the
LIFOQueue.
- __eq__(other: object) bool¶
Equality comparison
If
otheris aLIFOQueueand the corresponding elements ofselfandothercompare as equal, then returnTrue. Otherwise returnFalse.- Returns:
self == other
- __iter__() Iterator¶
Iteration
Iterate over current state in natural LIFO order.
- Returns:
Iterator of the data.
- __repr__() str¶
String representation
Construct string ‘LIFOQueue(d₁, d₂, … dₙ)’ where
d₁, d₂, … dₙ are the contents displayed with
repr()
- Returns:
A string to reproduce the
LIFOQueue.
- __str__() str¶
User string
Construct string ‘|| d₁ > d₂ > … > dₙ ><’ where
d₁, d₂, …, dₙ are the contents displayed with
str()
- Returns:
A string meaningful to an end user.
- copy() LIFOQueue[D]¶
Copy
Shallow copy the
LIFOQueue.- Returns:
New
LIFOQueueinstance containing the same references.
- push(*ds: D) None¶
Push
Push items onto
LIFOQueue.- Parameters:
ds – Items to be pushed onto
LIFOQueue.
- pop() MayBe¶
Pop
Pop newest data item off of
LIFOQueue.- Returns:
MayBeof popped data item ifLIFOQueuewas not empty, empty MayBe otherwise.
- peak() MayBe¶
Peak last
Peak at newest item on
LIFOQueue.- Returns:
MayBeof newest item on queue, emptyMayBeif queue empty.
- fold(f: Callable[[D, D], D]) MayBe[D]¶
- fold(f: Callable[[T, D], T], start: T) MayBe[T]
Fold
Reduces
LIFOQUEUEin natural LIFO Order, newest to oldest.- Parameters:
f – Reducing function, first argument is for accumulator.
start – Optional starting value.
- Returns:
MayBeof reduced value withf, emptyMayBeifLIFOQueueempty and no starting value given.