3{-| Represents an optional value. Maybe it is there, maybe it is not.
9@docs maybe, isJust, isNothing
15import Basics (not, (.))
18{-| The Maybe datatype. Useful when a computation may or may not
19result in a value (e.g. logarithm is defined only for positive
22data Maybe a = Just a | Nothing
24{-| Apply a function to the contents of a `Maybe`.
25Return default when given `Nothing`.
27maybe : b -> (a -> b) -> Maybe a -> b
28maybe b f m = case m of
32{-| Check if constructed with `Just`.
34isJust : Maybe a -> Bool
35isJust = maybe False (\_ -> True)
37{-| Check if constructed with `Nothing`.
39isNothing : Maybe a -> Bool
40isNothing = not . isJust
42cons mx xs = maybe xs (\x -> x :: xs) mx
44{-| Filters out Nothings and extracts the remaining values.
46justs : [Maybe a] -> [a]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list