tur/typeclass-functor
stdlib/typeclass-functor.tur
minimal Functor typeclass stub for typed-collection definstances.
Auto-loaded so list, vec, and other typed-collection modules can declare (definstance Functor [...] ...) without importing typeclass.tur.
Since: Phase TS5
defclass
Functor
(defclass Functor [^f])
map a function over every element of a container, keeping its shape.
Type parameters
| ^f | the container's type constructor (kind * -> *): Option, Cons, | |
| (Result _ B), Parser, ... |
Methods
(fmap [container :(f a) g :(fn [a] b)] :(f b))-
a container of the same shape as
containerwithgapplied to each element.gis a:fncarrier (tur_poly_fn_t), so a capturing closure can be passed directly.
Laws
(fmap c (fn [x] x)) = c (fmap (fmap c g) h) = (fmap c (fn [x] (h (g x))))
Example
(unwrap-or (fmap (some 20) (fn [x : int] : int (+ x 1))) 0) ; => 21
Instances
Backtrack, (Either E), Goal, Option, Parser, rc, (Result _ B), Schema
Since: Phase CCL