-
Notifications
You must be signed in to change notification settings - Fork 3
MonadFunctions
Robert Peszek edited this page Sep 22, 2013
·
1 revision
Monadic functions are defined in:
fpig.monad.functions.BaseM
For any implementation of MonadDescription
these can be used like so (this example uses MaybeMonad):
MonadDescription monad = MaybeMonad.instance
BaseM mf = BaseM.getInstance(monad)
//now monadic functions can be used with Maybe type:
assert just(5) == mf.mfilter(LARGER(4)) << just(5)
assert nothing() == mf.mfilter(LARGER(4)) << just(3)
assert just(5) == mf.join << just << just(5)
assert just(10) == mf.ap2(just(TIMES), just(5), just(2))
//...
For list of all monadic functions in BaseM see the groovy-doc. TODO link fpig.monad.functions.BaseM groovy doc.
In addition,
fpig.common.functions.FpigBase
defines a few functions which work for all registered monads. Here is an example:
def just3 = just(3)
unpure(just3) {
assert it == 3
}
For list of all FpigBase monadic functions, see FpigBase groovy-doc. TODO: link FpigBase groov-doc
Back to MonadPolymorphism