Lyric v1.6.0

std.option

Computing with ?T without testing first.

There is no Option<T> here — ?T is it, and these are functions over the built-in type. Absent on purpose, because the language already has them: unwrap is o!, unwrapOr is o ?? fallback, and isSome/isNone are o != null/o == null, which is what flow narrowing keys on. A function would cut that off: after if (isSome(o)), o would still be a ?T.

map function

pub fn map<T, U>(o: ?T, f: fn(T) -> U): ?U

Applies f to the value when there is one, and answers null when there is not.

stdlib/std/option.lyr:34

andThen function

pub fn andThen<T, U>(o: ?T, f: fn(T) -> ?U): ?U

As map, but f may itself come back empty.

This takes the place of flatten: a map whose f returned ?U would produce a ??U, which is not a type. Here f already returns ?U and the result is that same ?U.

stdlib/std/option.lyr:45

filter function

pub fn filter<T>(o: ?T, pred: fn(T) -> bool): ?T

Keeps the value only when pred accepts it, and answers null otherwise.

stdlib/std/option.lyr:53

zip function

pub fn zip<T, U>(a: ?T, b: ?U): ?(T, U)

Both present yields a tuple, otherwise null.

The result is taken apart with let (a, b) = ….

stdlib/std/option.lyr:66

contains function

pub fn contains<T :: [Equatable<T>]>(o: ?T, value: T): bool

Whether a value is present and equals value.

stdlib/std/option.lyr:77

toArray function

pub fn toArray<T>(o: ?T): T[]

Zero or one element — the bridge to anything that takes an array.

stdlib/std/option.lyr:87

OptionIterator class

pub class OptionIterator<T> :: [Iterator<T>]

The iterator iter hands out: yields the value once, if there is one.

value: ?T
done: bool
pub mut fn next(): ?T

The value on the first call, null on every one after it.

stdlib/std/option.lyr:95

iter function

pub fn iter<T>(o: ?T): OptionIterator<T>

An iterator over zero or one value.

Every adapter in std.iter then works on an optional, without std.iter knowing anything about ?T.

stdlib/std/option.lyr:115

expect function

pub fn expect<T>(o: ?T, message: string): T

The value, or a panic carrying message.

As o!, but with a message of your own: LYR-VM0007 reports that a value was missing, never which one.

stdlib/std/option.lyr:125