std.functor

Implementation of the Functor type

Types

type Functor f = { map : forall a b . (a -> b) -> f a -> f b }

A Functor represents an action on a parameterized type which does not change the structure with the mapped type.

The following laws should hold:

  • map id == id
  • map (f << g) == map f << map g

Values

let map ?functor : forall a a0 a1 . [std.functor.Functor a] -> (a0 -> a1) -> a a0 -> a a1

Apply the supplied function to the contents of f a, converting it to an f b

Examples
  • option.functor.map show_Int.show (Some 1) == Some "1"
  • result.functor.map show_Int.show (Some 1) == Ok "1"
  • list.functor.map show_Int.show (list.of [1, 2]) == list.of ["1", "2"]
Note
  • Known as fmap in Haskell