Monads/List monad: Difference between revisions
m
→{{header|Perl}}: 'strict' compliant, minor cleanup
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: 'strict' compliant, minor cleanup) |
|||
Line 412:
=={{header|Perl}}==
With the help of the CPAN module <code>Data::Monad</code>, we can work with list monads.
<lang perl>use
use feature 'say';
use Data::Monad::List;
# Cartesian product to 'count' in binary
my @cartesian = [(
list_flat_map_multi { scalar_list(join '', @_) }
scalar_list(0..1),
scalar_list(0..1),
scalar_list(0..1)
)->scalars]
say join "\n", @{shift @cartesian};
Line 427 ⟶ 428:
# Pythagorean triples
my @triples = [(
list_flat_map_multi { scalar_list(
{ $_[0] < $_[1] && $_[0]**2+$_[1]**2 == $_[2]**2 ? join(',',@_) : () }
Line 440 ⟶ 441:
}</lang>
{{out}}
<pre>
001
010
|