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

NAME

Data::Monad::Base::Sugar - Syntax sugars for Data::Monad.

SYNOPSIS

  use Data::Monad::Base::Sugar;
  use Data::Monad::List;

  my $result = Data::Monad::Base::Sugar::for {
      pick \my $x => sub { scalar_list 1 .. 100 };
      pick \my $y => sub { scalar_list $x .. 100 };
      pick \my $z => sub { scalar_list $y .. ($x + $y > 100 ? 100 : $x + $y) };
      satisfy { $x**2 + $y**2 == $z**2 };
      yield { $x, $y, $z }
  };

DESCRIPTION

Data::Monad::Base::Sugar provides syntax sugars for Data::Monad.

The for method is known as "do" expression in Haskell.

METHODS

$monad = Data::Monad::Base::Sugar::for { ... }

DSL to create a monad value. You can use following functions in the block, and shouldn't write sentences other than following functions in the block.

All sentences are connected by flat_map automatically.

pick \$value, \&f
pick \@values, \&f
pick \&f

Retrieves values from the monad, and puts it in $value. \&f should return any Monad objects.

You should handle $value as read-only and should use $value only in code-refs of other DSL functions.

let \$value, \&f
let \@values, \&f

Captures the value into $value. \&f can return any values, and the result is put in $value directly.

satisfy { ... }

Filters values by using filter.

yield { ... }

Wraps values in a Monad object by using unit and returns the monad object. This sentence should be the last line of DSL.

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.