APIMaybe

Maybe

Optional values.

A Maybe a holds either one value of type a or none. Use it where a value may legitimately be absent, such as a lookup that finds nothing, rather than a sentinel value that callers could mistake for a real one.

The prelude exposes the type and both constructors unqualified, and Maybe.withDefault qualified; import Maybe exposing (withDefault) brings the function into scope unqualified.

Maybe

type Maybe a    = Nothing    | Just aSource

A value of type a that may be absent. Values compare and display by constructor, with Nothing ordered before every Just.

Just 3 == Just 3
Nothing < Just 0
show (Just "a") == "Just \"a\""

Constructors

Nothing

Nothing : Maybe aSource

No value.

Just

Just : a -> Maybe aSource

A present value.

Instances:

Decode a => Decode (Maybe a)
Encode a => Encode (Maybe a)
Eq a => Eq (Maybe a)
Ord a => Ord (Maybe a)
Show a => Show (Maybe a)

withDefault

withDefault : a -> Maybe a -> aSource

The contained value, or fallback when there is none. The fallback is an ordinary argument, so it is evaluated before the call either way.

Maybe.withDefault 0 (Just 3) == 3
Maybe.withDefault 0 Nothing == 0