Groovy Documentation

com.github.mperry.fg.typeclass
[Groovy] Class Monad

java.lang.Object
  com.github.mperry.fg.typeclass.Applicative
      com.github.mperry.fg.typeclass.Monad

@groovy.transform.TypeChecked(TypeCheckingMode.SKIP)
abstract class Monad
extends Applicative

Created by MarkPerry on 30/12/13.

See Also:
http


Method Summary
M ap(M ma, M mf)

In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.

M apply(M t1, M t2)

Implements Applicative.apply using Monad combinators (<*>) :: f (a -> b) -> f a -> f b

F compose(F f, F g)

Right-to-left Kleisli composition of monads. (>=>), with the arguments flipped http://hackage.haskell.org/package/base-4.6.0.1/docs/Control-Monad.html#v:-60--61--60-

M filterM(java.util.List list, F f)

This generalizes the list-based filter function.

M flatMap(M ma, F f)

Sequentially compose two actions, passing any value produced by the first as an argument to the second. (>>=) :: forall a b. m a -> (a -> m b) -> m b

M fmap(F f, M ma)

Implements Functor interface using Monad combinators fmap :: (a -> b) -> f a -> f b

M foldM(Stream s, B b, F2 f)

The foldM function is analogous to foldl, except that its result is encapsulated in a monad.

M foldM(java.util.List s, B b, F2 f)

M foldM_(Stream s, B b, F2 f)

Like foldM, but discards the result.

M foldM_(java.util.List s, B b, F2 f)

M join(M mma)

The join function is the conventional monad join operator.

M liftM(M ma, F f)

Promote a function to a monad.

M liftM2(M ma, M mb, F2 f)

Promote a function to a monad, scanning the monadic arguments from left to right.

M liftM3(M ma, M mb, M mc, F3 f)

Promote a function to a monad, scanning the monadic arguments from left to right (cf. liftM2).

M map(M ma, F f)

M map2(M ma, M mb, F2 f)

M pure(A a)

Implements Applicative.pure using Monad combinators pure :: a -> f a

M replicateM(java.lang.Integer n, M ma)

replicateM n act performs the action n times, gathering the results.

M sequence(java.util.List list)

Evaluate each action in the sequence from left to right, and collect the results.

M skip(M ma)

M to(M ma, B b)

M traverse(java.util.List list, F f)

Map each element of a structure to an action, evaluate these actions from left to right and collect the results.

M unit(B b)

Inject a value into the monadic type.

F unit()

Returns a function representing unit

M unless(java.lang.Boolean b, M m)

The reverse of when.

M when(java.lang.Boolean b, M m)

Conditional execution of monadic expressions.

 
Methods inherited from class Applicative
apply, left, liftA, liftA2, liftA3, pure, right
 

Method Detail

ap

M ap(M ma, M mf)
In many situations, the liftM operations can be replaced by uses of ap, which promotes function application. return f `ap` x1 `ap` ... `ap` xn is equivalent to liftMn f x1 x2 ... xn ap :: Monad m => m (a -> b) -> m a -> m b Source


apply

M apply(M t1, M t2)
Implements Applicative.apply using Monad combinators (<*>) :: f (a -> b) -> f a -> f b


compose

F compose(F f, F g)
Right-to-left Kleisli composition of monads. (>=>), with the arguments flipped http://hackage.haskell.org/package/base-4.6.0.1/docs/Control-Monad.html#v:-60--61--60-
Parameters:
l
f
g
Returns:


filterM

M filterM(java.util.List list, F f)
This generalizes the list-based filter function. Arguments flipped compared to Haskell representation filterM :: Monad m => (a -> m Bool) -> [a] -> m [a]


flatMap

M flatMap(M ma, F f)
Sequentially compose two actions, passing any value produced by the first as an argument to the second. (>>=) :: forall a b. m a -> (a -> m b) -> m b


fmap

M fmap(F f, M ma)
Implements Functor interface using Monad combinators fmap :: (a -> b) -> f a -> f b


foldM

M foldM(Stream s, B b, F2 f)
The foldM function is analogous to foldl, except that its result is encapsulated in a monad. Note that foldM works from left-to-right over the list arguments. This could be an issue where (>>) and the `folded function' are not commutative. foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a Arguments are in different order


foldM

M foldM(java.util.List s, B b, F2 f)


foldM_

M foldM_(Stream s, B b, F2 f)
Like foldM, but discards the result. foldM_ :: Monad m => (a -> b -> m a) -> a -> [b] -> m ()


foldM_

M foldM_(java.util.List s, B b, F2 f)


join

M join(M mma)
The join function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level. join :: Monad m => m (m a) -> m a


liftM

M liftM(M ma, F f)
Promote a function to a monad. liftM :: Monad m => (a1 -> r) -> m a1 -> m r


liftM2

M liftM2(M ma, M mb, F2 f)
Promote a function to a monad, scanning the monadic arguments from left to right. For example, liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r


liftM3

M liftM3(M ma, M mb, M mc, F3 f)
Promote a function to a monad, scanning the monadic arguments from left to right (cf. liftM2). liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r


map

M map(M ma, F f)


map2

M map2(M ma, M mb, F2 f)


pure

M pure(A a)
Implements Applicative.pure using Monad combinators pure :: a -> f a


replicateM

M replicateM(java.lang.Integer n, M ma)
replicateM n act performs the action n times, gathering the results. replicateM :: Monad m => Int -> m a -> m [a] Source


sequence

M sequence(java.util.List list)
Evaluate each action in the sequence from left to right, and collect the results.
Parameters:
list
Returns:


skip

M skip(M ma)


to

M to(M ma, B b)


traverse

M traverse(java.util.List list, F f)
Map each element of a structure to an action, evaluate these actions from left to right and collect the results.
Parameters:
list
f
Returns:


unit

M unit(B b)
Inject a value into the monadic type. return :: a -> m a


unit

F unit()
Returns a function representing unit


unless

M unless(java.lang.Boolean b, M m)
The reverse of when. unless :: Monad m => Bool -> m () -> m () Source


when

M when(java.lang.Boolean b, M m)
Conditional execution of monadic expressions. For example, when debug (putStr "Debugging\n") will output the string Debugging\n if the Boolean value debug is True, and otherwise do nothing. when :: Monad m => Bool -> m () -> m ()


 

Groovy Documentation