structMaybe
struct Maybe<T>
items: [T]
endmaybe: a value that might not be there, and pairs and triples for giving back more than one thing. use "maybe.jamo"
A Maybe<T> holds one value or nothing. A function that might not find anything gives back a Maybe, and the code that called it checks has() before get(), or uses or_else for a fallback:
var hit = find_first(enemies, func(e: Enemy): bool => e.health > 0)
if hit.has()
hit.get().health -= 10
end
pair(a, b) and triple(a, b, c) bundle values, so a function can give back two or three things at once.
struct Maybe<T>
items: [T]
endfunc some<T>(value: T): Maybe<T>
A Maybe holding a value
func none<T>(): Maybe<T>
A Maybe holding nothing. Its type has to be given, like none<int>()
func Maybe<T>.has(): bool
func Maybe<T>.get(): T
The value. Stops with a clear error when there isn't one, so check has() first, or use or_else
func Maybe<T>.or_else(fallback: T): T
The value, or fallback when there isn't one
func find_first<T>(items: [T], keep: func(T): bool): Maybe<T>
The first item where keep(item) is true, or nothing
struct Pair<A, B>
first: A
second: B
endstruct Triple<A, B, C>
first: A
second: B
third: C
endfunc pair<A, B>(first: A, second: B): Pair<A, B>
func triple<A, B, C>(first: A, second: B, third: C): Triple<A, B, C>