本間 雅洋 (Masahiro Honma) > Data-Monad-0.05 > Data::Monad::Maybe

Download:
Data-Monad-0.05.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Source   Latest Release: Data-Monad-0.07

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.

syntax highlighting: