Lambdas builtins
6 builtins of Soma 3.2.4 in the category Lambdas, with their exact signatures, as soma describe --builtins --json prints them.
filter
filter(list: List, x => Bool) -> ListKeep elements where the lambda returns true (it answers a Bool; () counts as false).
Used in verified programs:
- agents/horde_audit, line 34: let high = verdicts.values() |> filter(v => v.risk == "high")
- finance/portfolio_pnl, line 44: return enriched() |> filter(p => p.pnl > 0.0)
- medical/prescription_lockout, line 88: let kept = filter(current, d => d != drug)
- records/employees, line 33: let rows = staff() |> filter(e => e.dept == dept)
find
find(list: List, x => Bool) -> AnyFirst element where the lambda returns true, or ().
Used in verified programs:
- records/ecs, line 42: let e = es |> find(x => x.id == id)
- records/inventory, line 23: let it = stock() |> find(i => i.sku == sku)
- records/students, line 28: let s = roster() |> find(x => x.name == name)
any
any(list: List, x => Bool) -> BoolTrue if the lambda returns true for at least one element.
Used in verified programs:
- games/pig_dice, line 22: if any(rolls, r => r == 1) { return 0 }
- games/snake, line 21: return any(snake, seg => seg.y == y && seg.x == x)
- games/yahtzee, line 35: if any(c, x => x >= n) { return sum(dice) }
- medical/bloodbank, line 63: return any(recips, r => r == recipient)
all
all(list: List, x => Bool) -> BoolTrue if the lambda returns true for every element (true on empty).
Used in verified programs:
- games/tic_tac_toe, line 29: return all(board, c => c != "")
count
count(list: List, x => Bool) -> IntNumber of elements where the lambda returns true.
Used in verified programs:
- data/ab_test, line 24: let conv = rows |> count(r => r.converted == 1)
- records/ecs, line 37: return world() |> count(e => e.hp.cur > 0)
- records/employees, line 25: return staff() |> count(e => e.dept == dept)
- records/kanban, line 38: "todo", count(vals, c => c.col == "todo"),
reduce
reduce(list: List, initial, p => expr) -> AnyFold the list; the lambda receives {acc, val} and returns the next acc.
Used in verified programs:
- data/group_reduce, line 26: return votes() |> reduce(0, p => p.acc + p.val.weight)
- math/gcd_lcm, line 25: return xs |> reduce(0, p => gcd(p.acc, p.val))