module splitend_node

Immutable data nodes used by splitend stacks.

SplitEnd node

Used to make inwardly directed bush-like graphs.

  • designed so multiple splitends can safely share the same data

  • nodes always contain data

  • data node SENode[D] make up end-to-root singularly linked lists

  • two nodes compare as equal if

    • both their previous Nodes are the same

    • their data compare as equal

  • a root node is a node whose previous node is itself

    • root nodes mark the bottom of splitend stacks

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

    • forming bush like graphs

class pythonic_fp.splitends.splitend_node.SENode

Bases: Generic

__init__(data: D, prev: Self | _Sentinel = _sentinel) None

init

param data:

Nodes always contain data of type D.

param prev:

Link to previous node, points to self if a root node.

__bool__() bool

bool

returns:

True only if SENode is not a root node.

__iter__() Iterator

iter

yields:

Node date until and including root node.

__eq__(other: object) bool

equality comparison

Two SENodes nodes are equal if their previous nodes are the same object and their data compare as equal.

param other:

returns:

True if other is a SplitEnd which compares as equal to self as described above.

Note

Will be useful when consolidating SplitEnds.

data() D

peak at data in SENode

returns:

The data stored in the SENode.

prev() Self

peak at previous node

returns:

The previous node stored in the SENode.

both() tuple[D, Self]

both data and previous node

Peak at data and previous node, if a root then data and self.

returns:

Tuple of type tuple[D, SENode[D]]

push(data: D) Self

push date to create new SENode[D]

param data:

Data for new node to contain.

returns:

New SENode whose previous node is the current node.

fold(f: Callable[[D, D], D]) D
fold(f: Callable[[T, D], T], init: T) T

fold

Fold data across linked nodes with a function.

param f:

Folding function, first argument is for accumulated value.`

param init:

Optional initial starting value for the fold.

returns:

Reduced value folded from end to root in natural LIFO order.