Skip to content
Open Saka

Functions

A function is a Flow with parameters:

def double(x! num)! num = x * 2
double(21) // {42}

Each parameter has a contract: x! num takes exactly one number. ! num after the parentheses promises exactly one number back.

* lets a parameter take a whole Bag:

def total_with_tax(amounts* num, rate! num)! num = sum(amounts) * (1 + rate)
total_with_tax({10, 20}, 0.5) // {45}

sum adds up a Bag of numbers; Grouping and summarizing lists functions like it.

A function declared with def lin runs once for each Value of its arguments. Its parameters stand for one Value each, so each has a Set and no cardinality, as in text: str:

def lin shout(text: str): str = "\{text}!"
shout({"hi", "bye"}) // {"bye!", "hi!"}

Many standard library functions work this way:

str::length({"one", "three"}) // {3, 5}