stm
Curried pipeline operators for |> - each function returns a lambda that accepts a list so you can chain list transformations elegantly. Covers map, filter, partition, take, drop, reverse, fold, concat, zip, zip-with, type assertion, unwrap-with-default, fixed-size chunking, length, and string-join.
Load with: use stm
What this module does
stm provides curried versions of the common trl list
operations so they compose naturally with ilusm's |> pipe
operator. Instead of trl.map(xs, f) you write
xs |> pmap(f). Each stage is a function-returning-function
that takes the list last, making pipelines read left-to-right.
Quick example
use stm
result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|> pfi(\(x) x % 2 == 0) # [2,4,6,8,10]
|> pmap(\(x) x * x) # [4,16,36,64,100]
|> ptake(3) # [4,16,36]
|> pfold(0, \(acc, x) acc + x) # 56
# Chunking
chunks = [1,2,3,4,5] |> pchun(2) # [[1,2],[3,4],[5]]
# String join
out = ["a","b","c"] |> pstrj(", ") # "a, b, c"
# Concat
extended = [1,2,3] |> pcat([4,5,6]) # [1,2,3,4,5,6]
Operators
Transformation
pmap(fn)Returns \(xs) trl.map(xs, fn). Apply fn to every element.
pfi(pred)Returns \(xs) trl.fil(xs, pred). Keep elements where pred is truthy.
ppart(pred)Returns \(xs) trl.trlpa(xs, pred). Split into {yes, no} partitions.
pfold(z0, fn)Returns \(xs) trl.fld(xs, z0, fn). Left fold with initial value.
prevA lambda \(xs) trl.rev(xs). Reverse the list.
pchun(n)Returns a lambda that splits a list into chunks of size n. The last chunk may be smaller.
Slicing and combining
ptake(n)Returns \(xs) trl.take(xs, n). Keep first n elements.
pdrop(n)Returns \(xs) trl.drop(xs, n). Skip first n elements.
pcat(ys)Returns \(xs) trl.cat(xs, ys). Append ys to the piped list.
pzipReturns a curried zip: xs |> pzip |> ys pairs elements from both lists.
pzipw(fn)Returns a curried zip-with: pairs elements and applies fn(a, b) to each pair.
Terminal and utility
plenLambda \(xs) len(xs). Returns the list length as a pipeline terminal.
pstrj(sep)Returns \(xs) txt.jn(xs, sep). Joins a string list with separator.
punwr(default)Returns \(x) if x == nil: default | x. Unwraps a nil-safe value.
asty(ty)Returns \(v) hy_assert(v, ty). Asserts a hybrid runtime type in the pipeline.
Notes
- Requires
trl,txt, andhybrid_rt.