Monads
Monadics

Prev:Applicative Functors
Next:Monadic Implementation Quirks


Monads are datastructures for which there exists a notion of sequential operation, composed by the and-then/>>= combinator:
( M-x quot: ( x -- M-y ) -- M-y )


For the Maybe and Either types this encompasses the concept of validation, or short circuiting:
USING: strings monadics quotations prettyprint unicode ; : trivial-password-validator ( string -- Maybe-string ) just [ [ lower? not ] guard-maybe ] >>= [ [ upper? not ] guard-maybe ] >>= ; "hello" trivial-password-validator .
Nothing


In a sequence context, the quotation permutes over each element:
USING: ranges math monadics quotations prettyprint ; { 1 2 3 4 } [ [ 0 ] dip (a..b] ] >>= .
V{ 1 1 2 1 2 3 1 2 3 4 }