module de

class pythonic_fp.queues.de.DEQueue(*dss: Iterable)

Stateful Double-Ended (DE) Queue data structure.

  • O(1) pops each end

  • O(1) amortized pushes each end

  • 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

Parameters:

dss – “Optionally” takes a single iterable to initialize data in FIFO order.

Raises:
  • TypeError – When dss[0] not Iterable.

  • ValueError – If more than 1 iterable is given.

__init__(*dss: Iterable) None
Parameters:

dss – “Optionally” takes a single iterable to initialize data in FIFO order.

Raises:
  • TypeError – When dss[0] not Iterable.

  • ValueError – If more than 1 iterable is given.

__eq__(other: object) bool

Return self==value.

__repr__() str

Return repr(self).

__str__() str

Return str(self).

copy() DEQueue[D]

Shallow copy.

Returns:

Shallow copy of the DEQueue.

pushl(*ds: D) None

Push data onto left side of DEQueue.

Parameters:

ds – Items to be pushed onto DEQueue from the left.

pushr(*ds: D) None

Push data onto right side of DEQueue.

Parameters:

ds – Items to be pushed onto DEQueue from the right.

popl() MayBe

Pop next item from left side DEQueue, if it exists.

Returns:

MayBe of popped item if queue was not empty, empty MayBe otherwise.

popr() MayBe

Pop next item off right side DEQueue, if it exists.

Returns:

MayBe of popped item if queue was not empty, empty MayBe otherwise.

peakl() MayBe

Peak left side of DEQueue. Does not consume item.

Returns:

MayBe of leftmost item if queue not empty, empty MayBe otherwise.

peakr() MayBe

Peak right side of DEQueue. Does not consume item.

Returns:

MayBe of rightmost item if queue not empty, empty MayBe otherwise.

foldl(f: Callable[[D, D], D]) MayBe[D]
foldl(f: Callable[[L, D], L], start: L) MayBe[L]

Reduces DEQueue left to right.

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

  • start – Optional starting value.

Returns:

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

foldr(f: Callable[[D, D], D]) MayBe[D]
foldr(f: Callable[[D, R], R], start: R) MayBe[R]

Reduces DEQueue right to left.

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

  • start – Optional starting value.

Returns:

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

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

Map left to right.

Tip

Order map done does not matter if f is pure.

Parameters:

f – Function to map over queue.

Returns:

New DEQueue instance, retain original order.

pythonic_fp.queues.de.de_queue(*ds: D) DEQueue

DEQueue factory function.

Parameters:

ds – Initial items as if pushed on from right to left.

Returns:

DEQueue with items initialized in FIFO order.