Data::Monad::Base::Sugar - Syntax sugars for Data::Monad.
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 } };
Data::Monad::Base::Sugar provides syntax sugars for Data::Monad.
The for method is known as "do" expression in Haskell.
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.
flat_map
Retrieves values from the monad, and puts it in $value. \&f should return any Monad objects.
$value
\&f
You should handle $value as read-only and should use $value only in code-refs of other DSL functions.
Captures the value into $value. \&f can return any values, and the result is put in $value directly.
Filters values by using filter.
filter
Wraps values in a Monad object by using unit and returns the monad object. This sentence should be the last line of DSL.
unit
hiratara <hiratara {at} cpan.org>
Data::Monad::Base::Monad
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Data::Monad, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Monad
CPAN shell
perl -MCPAN -e shell install Data::Monad
For more information on module installation, please visit the detailed CPAN module installation guide.