module Stdlib.Data.Maybe.Base;

--- Represents an optional value that may or may not be present. Provides a way
--- to handle null or missing values in a type-safe manner.
type Maybe A :=
  | nothing
  | just A;

--- Extracts the value from a ;Maybe; if present, else returns the given value.
{-# inline: true #-}
fromMaybe {A} (a : A) : Maybe A  A
  | nothing := a
  | (just a) := a;

--- Applies a function to the value from a ;Maybe; if present, else returns the
--- given value.
{-# inline: true #-}
maybe {A B} (b : B) (f : A  B) : Maybe A  B
  | nothing := b
  | (just a) := f a;
Last modified on 2023-11-29 16:11 UTC