std.applicative
Implementation of the Applicative
type
Types
#[implicit]
type Applicative f = {
functor : Functor f,
apply : forall a b . f (a -> b) -> f a -> f b,
wrap : forall a . a -> f a
}
A Functor
with application.
The following laws should hold:
wrap id <*> v = v
wrap (<<) <*> u <*> v <*> w = u <*> (v <*> w)
wrap f <*> wrap x = wrap (f x)
u <*> wrap y = wrap (\g -> g x) <*> u
Values
let apply ?app : forall b a f . [Applicative f] -> f (a -> b) -> f a -> f b
Like functor.map
, but this time the supplied function is embedded in f
Note
- Known as
(<*>)
in Haskell
let wrap ?app : forall a f . [Applicative f] -> a -> f a
Wrap the supplied value in f
Examples
option.applicative.wrap 1 == Some 1
result.applicative.wrap 1 == Ok 1
list.applicative.wrap 1 == list.of [1]
Note
- Known as
pure
in Haskell
#[infix(left, 4)]
let <*> : forall b a f . [Applicative f] -> f (a -> b) -> f a -> f b
Alias of <*>
#[infix(left, 4)]
let <* l r : forall b a f . [Applicative f] -> f a -> f b -> f a
Sequence actions, discarding the value of the second argument
#[infix(left, 4)]
let *> l r : forall b a f . [Applicative f] -> f a -> f b -> f b
Sequence actions, discarding the value of the first argument
let map2 fn a b : forall c b a f . [Applicative f] -> (a -> b -> c) -> f a -> f b -> f c
Maps over two actions
let map3 fn a b c : forall d c b a f .
[Applicative f] -> (a -> b -> c -> d) -> f a -> f b -> f c -> f d
Maps over three actions