soma.cell

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) -> List

Keep elements where the lambda returns true (it answers a Bool; () counts as false).

deterministic · replay: pure

Used in verified programs:

find

find(list: List, x => Bool) -> Any

First element where the lambda returns true, or ().

deterministic · replay: pure

Used in verified programs:

any

any(list: List, x => Bool) -> Bool

True if the lambda returns true for at least one element.

deterministic · replay: pure

Used in verified programs:

all

all(list: List, x => Bool) -> Bool

True if the lambda returns true for every element (true on empty).

deterministic · replay: pure

Used in verified programs:

count

count(list: List, x => Bool) -> Int

Number of elements where the lambda returns true.

deterministic · replay: pure

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) -> Any

Fold the list; the lambda receives {acc, val} and returns the next acc.

deterministic · replay: pure

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))