splitends.splitend¶
LIFO stacks safely sharing immutable data between themselves.
- class pythonic_fp.splitends.splitend.SplitEnd(root_data: D, *data: D)¶
Like one of many “split ends” from a shaft of hair, a
splitendcan be “snipped” shorter or “extended” further from its “tip”. Its root is irremovable and cannot be “snipped” off. While mutable, different splitends can safely share data with each other.- Parameters:
root_data – irremovable initial data at bottom of stack
data – removable data to be pushed onto splitend stack
- copy() SplitEnd[D]¶
Return a copy of the SplitEnd. O(1) space & time complexity.
- Returns:
a new SplitEnd instance with same data and root
- extend(*ds: D) None¶
Add data onto the tip of the SplitEnd. Like adding a hair extension.
- Parameters:
ds – data to extend the splitend
- fold(f: Callable[[T, D], T], init: T | None = None) T¶
Reduce with a function, fold in natural LIFO Order.
- Parameters:
f – folding function, for argument is for the accumulator
init – optional initial starting value for the fold
- Returns:
reduced value folding from tip to root in natural LIFO order
- peak() D¶
Return data from tip of SplitEnd, do not consume it.
- Returns:
data at the end of the SplitEnd
- rev_fold(f: Callable[[T, D], T], init: T | None = None) T¶
Reduce with a function, fold from root to tip.
- Parameters:
f – folding function, for argument is for the accumulator
init – optional initial starting value for the fold
- Returns:
reduced value folding from tip to root in natural LIFO order
- snip() D¶
Snip data off tip of SplitEnd. Just return data if tip is root.
- Returns:
data snipped off tip, otherwise root data if tip is root