The Monad trait defines the basic operations over a /monad/,
a concept from a branch of mathematics known as /category theory/.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an /abstract datatype/ of actions.
Scala's for
expressions provide a convenient syntax for writing
monadic expressions.
Instances of 'Monad' should satisfy the following:
Left identity
(pure[F](a) >>= f) == f(a)
Right identity
(fa >>= {(x: A) => pure[F](x) }) == fa
Associativity
(m >>= { (x: A) => k(x) >>= h }) == ((m >>= k) >>= h)
Furthermore, the 'Monad' and 'Applicative' operations should relate as follows:
map[F](f)(xs) == (xs >>= (pure[F] compose f))
>> == *>
and that meow.control.Applicative#pure and meow.control.Applicative#<*> satisfy the Applicative functor laws.
- Companion
- object
Value members
Extensions
Extensions
Right-to-left composition of Kleisli arrows.
Right-to-left composition of Kleisli arrows.
- Example
val ff1 = (x:Int) => Option(x +1) val ff2 = (x:Int) => Option(x +2) (ff2 <=< ff1) =<< Option(1) == Option(4)
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
- Example
Option(1) >> Option(2) == Option(2)