
Data::Monad::Maybe - The Maybe monad.

use Data::Monad::Maybe;
sub div {
my ($n, $m) = @_;
$m == 0 ? nothing : just($n / $m);
}
# answer: 1.5
print just(3, 2)->flat_map(\&div)
->map(sub { "answer: $_[0]" })
->value, "\n";
# nothing
print "nothing\n" if just(3, 0)->flat_map(\&div)
->map(sub { "answer: $_[0]" })
->is_nothing;

Data::Monad::Maybe represents optional values.
This module is marked EXPERIMENTAL. API could be changed without any notice.

Is the constructors of this class.
Overrides methods of Data::Monad::Base::Monad.
Overrides methods of Data::Monad::Base::MonadZero.
Checks if $maybe contains any values.
Returns a list of values which is contained by $maybe.

hiratara <hiratara {at} cpan.org>


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.