The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

  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;

DESCRIPTION

Data::Monad::Maybe represents optional values.

This module is marked EXPERIMENTAL. API could be changed without any notice.

METHODS

$maybe = just(@values)
$maybe = nothing()

Is the constructors of this class.

unit
flat_map

Overrides methods of Data::Monad::Base::Monad.

zero

Overrides methods of Data::Monad::Base::MonadZero.

$maybe->is_nothing

Checks if $maybe contains any values.

@values = $maybe->value

Returns a list of values which is contained by $maybe.

AUTHOR

hiratara <hiratara {at} cpan.org>

SEE ALSO

Data::Monad::Base::Monad

LICENSE

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