Pages
Standard Library
Search
Entities
Maybe
Functions
Maps the value of a maybe with a possibility to discard it.
Maybe::Just(4)
|> Maybe.andThen((num : Number) : Maybe(String) {
if (num > 4) {
Maybe::Just(Number.toString(num))
}
else {
Maybe::Nothing
}
})
Flattens a nested maybe.
(Maybe.just("A")
|> Maybe.just()
|> Maybe.flatten()) == Maybe.just("A")
Returns whether or not the maybe is just a value or not.
Maybe.isJust(Maybe.just("A")) == true
Maybe.isJust(Maybe.nothing()) == false
Returns whether or not the maybe is just nothing or not.
Maybe.isNothing(Maybe.just("A")) == false
Maybe.isNothing(Maybe.nothing("A")) == false
Returns a maybe containing just the given value.
Maps the value of a maybe.
(Maybe.just(1)
|> Maybe.map((number : Number) : Number { number + 2 })) == 3
Returns nothing.
Returns the first maybe with value of the array or nothing if it's all nothing.
Maybe.oneOf([Maybe.just("A"), Maybe.nothing()]) == Maybe.just("A")
Converts the maybe to a result using the given value as the error.
Maybe.toResult("Error", Maybe.nothing()) == Result.error("Error")
Maybe.toResult("Error", Maybe.just("A")) == Result.ok("A")
Returns the value of a maybe or the given value if it's nothing.
Maybe.withDefault("A", Maybe.nothing()) == "A"
Maybe.withDefault("A", Maybe.just("B")) == "B"
Returns the value of a maybe, or calls the given func otherwise.
Maybe.withLazyDefault(() { "A" }, Maybe.nothing()) == "A"
Maybe.withLazyDefault(() { "A" }, Maybe.just("B")) == "B"