4 ms·
Or in perl: join "\n", map { $_->{description} } grep { $_->{description} ne "" } @mylist; sorry, every time i see something like this, i just can't resist
by hippich 14y ago
Or in perl:
join "\n", map { $_->{description} } grep { $_->{description} ne "" } @mylist;
sorry, every time i see something like this, i just can't resist to post code in Perl. =)
- deleted 14y ago[deleted]
- cygx 14y agoI'll see your Perl5 and raise you some Perl6: @list.map(*.description).grep(?*).join("\n")
- gecko 14y agoThat is starting to look more like J or K than Perl. Is the Perl 6 team still considering syntax changes? If so, any thought on making map/grep/join operators?
- cygx 14y agomap, grep and join are subs as well as methods. Perl6 is a multi-paradigm language and of course there's more than one way to do it - even when using the same operations. Instead of chaining methods, one could also use # p5 style join "\n", grep ?*, map *.description, @list; # dataflow style @list ==> map *.description ==> grep ?* ==> join "\n"; join "\n" <== grep ?* <== map *.description <== @list;
- draegtun 14y agoPerl6 allows you to define your own operators: $ perl6 > sub infix:<J> ($sep, @list) { @list.join($sep) } > sub prefix:<J,> (@list) { @list.join(',') } > ':' J <one two three four>; one:two:three:four > J,<five six seven eight>; five,six,seven,eight
- yen223 14y agoThat can't be Perl, I actually understood it.