Monads/List monad: Difference between revisions

m
→‎{{header|Perl}}: 'strict' compliant, minor cleanup
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 feature 'say'strict;
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>0,0,0000
000
001
010
2,392

edits