filo

class pythonic_fp.queues.fifo.FIFOQueue

Bases: Generic

FIFOQueue

Stateful First-In-First-Out (FIFO) Queue data structure.

  • O(1) pops

  • O(1) amortized pushes

  • O(1) length determination

  • in a Boolean context, truthy if not empty, falsy if empty

  • will automatically increase storage capacity when needed

  • neither indexable nor sliceable by design

__init__(*ds: Iterable) None

Initializer

Initialize FIFOQueue with 0 or 1 iterables to populate the queue in natural FIFO 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

FIFOQueue truthy when non-empty, falsy when empty.

__len__() int

Get length

Return the number of data elements in the FIFOQueue.

__eq__(other: object) bool

Equality comparison

If other is a FIFOQueue 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 FIFO order.

Returns:

An iterator of the data.

__repr__() str

String representation

Construct string ‘FIFOQueue(d₁, d₂, … dₙ)’ where

  • d₁, d₂, … dₙ are the contents displayed with repr()

Returns:

A string to reproduce the FIFOQueue.

__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() FIFOQueue[D]

Copy

Shallow copy the FIFOQueue.

Returns:

New FIFOQueue instance containing the same references.

push(*ds: D) None

Push

Push data items onto FIFOQueue.

Parameters:

ds – Items to be pushed onto ‘’FIFOQueue’’.

pop() MayBe

Pop

Pop oldest data item off of FIFOQueue.

Returns:

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

peak_last_in() MayBe

Peak last

Peak at newest item on FIFOQueue.

Returns:

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

peak_next_out() MayBe

Peak next out

Peak at oldest data item on FIFOQueue.

Returns:

MayBe of oldest item on FIFOQueue, empty MayBe if FIFOueue empty.

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

Fold

Reduces FIFOQueue in natural FIFO Order, oldest to newest.

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

  • start – Optional starting value.

Returns:

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

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

Map

Map f over the FIFOQueue, retain original order.

Parameters:

f – Function to map over FIFOQueue.

Returns:

New FIFOQueue instance.

pythonic_fp.queues.fifo.fifo_queue(*ds: D) FIFOQueue

Create FIFOQueue

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

Parameters:

ds – Initial data to be pushed on in FIFO order.

Returns:

New FIFOQueue instance.