-
Notifications
You must be signed in to change notification settings - Fork 0
API Maybe
- Maybe(hasValue, [value])
- isJust(maybe)
- isNothing(maybe)
- maybe(defaultValue, f, maybe)
- fromMaybe(defaultValue, maybe)
- catMaybes(xs)
- mapMaybe(f, xs)
hasValue : Boolean
value : Any (only required if hasValue)
return : Maybe
- Functor
- Monad
- Applicative
Create a Maybe.
A Maybe with hasValue = true and value = 1 will be described in the documentation as Just 1. A Maybe with hasValue = false will be described as Nothing.
var exists = new tlc.Maybe(true, 1);
var doesNotExist = new tlc.Maybe(false);
tlc.map(tlc.op["+"](1), exists); // Just 2
tlc.map(tlc.op["+"](1), doesNotExist); // NothingisJust : Maybe a -> Boolean
maybe : Maybe
return : Boolean
Return true if maybe is a Just. Otherwise, return false.
isNothing : Maybe a -> Boolean
maybe : Maybe
return : Boolean
Return true if maybe is a Nothing. Otherwise, return false.
maybe : a -> (a -> b) -> Maybe a -> b
defaultValue : Any
f: Function
maybe: Maybe
return : Any
If maybe is a Just, return the application of f to its value. Otherwise, return defaultValue.
fromMaybe : a -> Maybe a -> a
defaultValue : Any
maybe: Maybe
return : Any
If maybe is a Just, return its value. Otherwise, return defaultValue.
catMaybes : [Maybe a] -> [a]
xs : Array of Maybes
return : Array
Removes all Nothings from xs and unwraps all Justs. So [Nothing, Just 1, Just 2] will become [1, 2].
mapMaybe : (a -> Maybe b) -> [a] -> [b]
f : Function returning a Maybe
xs : Array of Maybes
return : Array
Maps f over xs and then catMaybes.