Skip to content
Try Kata

core.opt

Optional values: a payload or an explicit absence.

All modules · Writing docstrings

enum Opt[T]

A value that may be absent. Match Val(value) or Non() to handle both cases.

let missing = Opt[Int].Non
print(missing.unwrap_or(7))
7

Source, line 12

Val(T)

A present value of type T.

Source, line 14

Non

No value.

Source, line 16

impl Opt[@T]

Source, line 19

func unwrap(self): T

Return the payload. Stop with an error if this is Non.

Source, line 21

func unwrap_or(self, default: T): T

Return the payload, or default when absent. Arguments are evaluated before the call.

Source, line 29