| 1 |
// Extend above example to sanity check input. |
| 2 |
local equal_parts(size, ingredients) = |
| 3 |
local qty = size / std.length(ingredients); |
| 4 |
// Check a pre-condition |
| 5 |
if std.length(ingredients) == 0 then |
| 6 |
error 'Empty ingredients.' |
| 7 |
else [ |
| 8 |
{ kind: i, qty: qty } |
| 9 |
for i in ingredients |
| 10 |
]; |
| 11 |
|
| 12 |
local subtract(a, b) = |
| 13 |
assert a > b : 'a must be bigger than b'; |
| 14 |
a - b; |
| 15 |
|
| 16 |
assert std.isFunction(subtract); |
| 17 |
|
| 18 |
{ |
| 19 |
test1: equal_parts(1, ['Whiskey']), |
| 20 |
test2: subtract(10, 3), |
| 21 |
object: { |
| 22 |
assert self.f < self.g : 'wat', |
| 23 |
f: 1, |
| 24 |
g: 2, |
| 25 |
}, |
| 26 |
assert std.isObject(self.object), |
| 27 |
} |