lifo

class pythonic_fp.queues.lifo.LIFOQueue

Bases: Generic

LIFOQueue

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 LIFOQueue with 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

LIFOQueue truthy 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 other is a LIFOQueue and the corresponding elements of self and other compare as equal, then return True. Otherwise return False.

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 LIFOQueue instance 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:

MayBe of popped data item if LIFOQueue was not empty, empty MayBe otherwise.

peak() MayBe

Peak last

Peak at newest item on LIFOQueue.

Returns:

MayBe of newest item on queue, empty MayBe if queue empty.

fold(f: Callable[[D, D], D]) MayBe[D]
fold(f: Callable[[T, D], T], start: T) MayBe[T]

Fold

Reduces LIFOQUEUE in natural LIFO Order, newest to oldest.

Parameters:
  • f – Reducing function, first argument is for accumulator.

  • start – Optional starting value.

Returns:

MayBe of reduced value with f, empty MayBe if LIFOQueue empty and no starting value given.

map(f: Callable[[D], U]) LIFOQueue

Map

Map f over the LIFOQueue, retain original order.

Parameters:

f – Function to map over LIFOQueue.

Returns:

New LIFOQueue instance.

pythonic_fp.queues.lifo.lifo_queue(*ds: D) LIFOQueue

Create LIFOQueue

Factory function to create an LIFOQUEUE instance from the function’s arguments.

Parameters:

ds – Items pushed onto queue in LIFO order.

Returns:

New LIFOQueue instance.