pythonic-fp.splitends API

Splitends Package

Pythonic FP - Splitends

Package implementing a singularly linked LIFO queue called a SplitEnd. These data structures can safely share data nodes between themselves.

Splitend Stack

SplitEnd stack related data structures

With use I am finding this data structure needs some sort of supporting infrastructure. Hence I split the original splitend module out to be its own subpackage.

class pythonic_fp.splitends.splitend.SplitEnd(root_data, *ds)

LIFO stacks which can safely share immutable data between themselves.

  • each SplitEnd is a very simple stateful (mutable) LIFO stack

  • data can be pushed and popped to the stack

  • the first value pushed onto the SplitEnd becomes it “root”

  • different mutable split ends can safely share the same “tail”

  • each SplitEnd sees itself as a singularly linked list

  • bush-like datastructures can be formed using multiple SplitEnds

  • len() returns the number of elements on the SplitEnd stack

  • in boolean context, return true if split end is not the “root”

copy()

Return a copy of the SplitEnd.

  • O(1) space & time complexity.

  • returns a new instance with same data, including the root

Return type:

SplitEnd[~D]

fold(f, init=None, /)

Reduce with a function, fold in natural LIFO Order.

Return type:

Union[T, Never]

peak()

Return the data at the top of the SplitEnd, doesn’t consume it.

Return type:

~D

pop()

Pop data off of the top of the SplitEnd. Re-root SplitEnd if root is popped off.

Return type:

Union[~D, Never]

push(*ds)

Push data onto the top of the SplitEnd.

Return type:

None

Splitend Stack Node

Data node class used privately by class SplitEnd.

Node classes used with graph-like data structures. API designed to be used by other data structures which contain these data structures.

class pythonic_fp.splitends.splitend_node.SENode(data, prev=MayBe())

Data node for class SplitEnd

  • hashable data node for a end-to-root singularly linked list.

  • designed so multiple splitends can safely share the same data

  • this type of node always

    • contain data

    • potential link to previous node

  • nodes point towards a unique “bottom node” with no predecessor

    • in a Boolean context returns true if not at the bottom

    • multiple bottom nodes can exist

  • two nodes compare as equal if

    • both their previous Nodes are the same

    • their data compares as equal

  • more than one node can point to the same proceeding node

    • forming bush like graphs

fold(f, init=None)

Reduce data across linked nodes.

  • with a function and an optional starting value

  • reduces in natural LIFO order, from self to the root

Return type:

T

peak()

Return contained data

Return type:

~D

pop2()

Return the data at the end and potential tail.

Return type:

tuple[~D, MayBe[SENode[~D]]]

push(data)

Push data onto the queue and return a new node containing the data.

Return type:

SENode[~D]