Maybe - Factor Documentation

Maybe
Monadics

Next: Either


Vocabulary
monadics

Word description
A Maybe either holds Just a value or is Nothing. Operations done on Nothing will return Nothing:
USING: math monadics prettyprint ; 5 just [ 1 + ] fmap .
T{ Just { value 6 } }

USING: math monadics prettyprint ; [ + ] 5 just <$> Nothing <*> .
Nothing

Just values are constructed with the just word, or turned from a generalized boolean by >maybe .

Not to be confused with the all-lowercase maybe .

Definition
IN: monadics

MIXIN: Maybe INSTANCE: Just Maybe INSTANCE: Nothing Maybe


Methods
USING: monadics ;

M: Maybe and-then fmap (maybe-join) ;


USING: kernel monadics ;

M: Maybe choose dup Nothing? [ drop ] [ nip ] if ;


USING: accessors kernel monadics ;

M: Maybe fmap
over Just? [ [ value>> ] dip lazy-call just ] [ drop ] if ;


USING: monadics ;

M: Maybe pure just ;


USING: accessors kernel monadics ;

M: Maybe reify
2dup [ Just? ] bi@ and
[ [ value>> ] bi@ swap lazy-call just ] [ 2drop Nothing ] if
;

AltStyle によって変換されたページ (->オリジナル) /