Documentation

Hale.Base.Data.Maybe

@[inline]
def Data.Maybe.maybe {β : Sort u_1} {α : Type u_2} (b : β) (f : αβ) :
Option αβ

Case analysis on Option (Haskell's maybe).

$$\text{maybe}(b, f, \text{none}) = b, \quad \text{maybe}(b, f, \text{some}\;a) = f(a)$$

Equations
Instances For
    @[inline]
    def Data.Maybe.fromMaybe {α : Type u_1} (d : α) :
    Option αα

    Extract from Option with a default (Haskell's fromMaybe).

    $$\text{fromMaybe}(d, \text{none}) = d, \quad \text{fromMaybe}(d, \text{some}\;a) = a$$

    Equations
    Instances For
      @[inline]
      def Data.Maybe.isJust {α : Type u_1} :
      Option αBool

      Test if some (Haskell's isJust).

      Equations
      Instances For
        @[inline]
        def Data.Maybe.isNothing {α : Type u_1} :
        Option αBool

        Test if none (Haskell's isNothing).

        Equations
        Instances For
          def Data.Maybe.catMaybes {α : Type u_1} :
          List (Option α)List α

          Collect some values from a list (Haskell's catMaybes).

          $$\text{catMaybes}([x_1, \ldots, x_n]) = [a \mid x_i = \text{some}\;a]$$

          Equations
          Instances For
            def Data.Maybe.mapMaybe {α : Type u_1} {β : Type u_2} (f : αOption β) :
            List αList β

            Map and filter in one pass (Haskell's mapMaybe).

            $$\text{mapMaybe}(f, xs) = \text{catMaybes}(\text{map}\;f\;xs)$$

            Equations
            Instances For
              @[inline]
              def Data.Maybe.listToMaybe {α : Type u_1} :
              List αOption α

              First element or none (Haskell's listToMaybe).

              Equations
              Instances For
                @[inline]
                def Data.Maybe.maybeToList {α : Type u_1} :
                Option αList α

                Option to singleton or empty list (Haskell's maybeToList).

                Equations
                Instances For
                  def Data.Maybe.fromJust {α : Type u_1} (o : Option α) :
                  o.isSome = trueα

                  Safe unwrap with proof that value is some (Haskell's fromJust made safe).

                  $$\text{fromJust}(\text{some}\;a, \_) = a$$

                  Equations
                  Instances For
                    theorem Data.Maybe.maybe_none {β : Sort u_1} {α : Type u_2} (b : β) (f : αβ) :
                    maybe b f none = b

                    maybe on none returns the default.

                    theorem Data.Maybe.maybe_some {β : Sort u_1} {α : Type u_2} (b : β) (f : αβ) (a : α) :
                    maybe b f (some a) = f a

                    maybe on some applies the function.

                    theorem Data.Maybe.fromMaybe_none {α : Type u_1} (d : α) :

                    fromMaybe on none returns the default.

                    theorem Data.Maybe.fromMaybe_some {α : Type u_1} (d a : α) :
                    fromMaybe d (some a) = a

                    fromMaybe on some extracts the value.

                    catMaybes of empty list is empty.

                    theorem Data.Maybe.mapMaybe_nil {α : Type u_1} {β : Type u_2} (f : αOption β) :

                    mapMaybe of empty list is empty.