soma.cell

Pipe operators

Pipe operators, in the reference of the Soma programming language (soma 3.2.4). A block marked ✓ is a whole program that soma check accepts; the others are excerpts.

// Higher-order (with lambdas)
data |> map(s => s.name)
data |> filter(s => s.score > 50)
data |> find(s => s.id == target)
data |> any(s => s.active)
data |> all(s => s.valid)
data |> count(s => s.score > 80)
data |> reduce(0, p => p.acc + p.val)

// Field-based
data |> filter_by("price", ">", 100)     // operators: > >= < <= == !=
data |> sort_by("score", "desc")
data |> top(10)
data |> bottom(5)
data |> group_by("dept")
data |> distinct("category")              // unique values

// Aggregates
data |> sum_by("qty")                     // sum of a field
data |> avg_by("qty")                     // average (Int if whole, else Float)
data |> min_by("qty")                     // row with smallest field value
data |> max_by("qty")                     // row with largest field value
data |> count_by("status", "open")        // count rows where field == value
data |> pluck("name")                     // list of one field's values
data |> select("id", "name")              // project each row to listed fields
data |> agg("dept", "qty:sum", "qty:avg") // group + aggregate; ops: sum avg min max count

// Utilities
data |> flatten()
data |> reverse()
data |> zip(other)
list("a", "b", "c") |> join(", ")        // "a, b, c"