Builtins and Libraries
3.1 Global Utilities
3.2 Numbers
3.3 Strings
3.4 Booleans
3.5 Raw  Array
3.6 Tables
3.7 lists
3.8 sets
3.9 arrays
3.10 string-dict
3.11 option
3.12 pick
3.13 either
3.14 srcloc
3.15 pprint
3.16 s-exp
3.17 s-exp-structs
3.18 image-structs
3.19 image
3.20 world
3.21 reactors
3.22 plot
On this page:
3.11.1 The Option Datatype
Option
none
some
is-none
is-some
3.11.2 Option Methods
.and-then
.or-else

3.11 option

Usage:

include option

import option as ...

3.11.1 The Option Datatype

data Option<a>:
| none
| some(value :: a)
end

none :: Option<a>
some :: (value :: a) -> Option<a>
is-none :: (val :: Any) -> Boolean
is-some :: (val :: Any) -> Boolean
3.11.2 Option Methods
.and-then :: (f :: (a -> b)) -> Option<b>

For none, returns none. For some, applies f to the value field and returns a new some with the updated value.

Examples:

check: add1 = lam(n): n + 1 end n = none n.and-then(add1) is none s = some(5) s.and-then(add1) is some(6) end

.or-else :: (v :: a) -> a

For none, returns v. For some, returns the value field. Useful for providing default values.

Examples:

check: n = none n.or-else(42) is 42 s = some(5) s.or-else(10) is 5 end