Schwartzian Transform built-in to Perl 6?

W

William James

The PerlFAQ says:
----------------------------------------------------------------------------
Here's an example of how to pull out the first word after the
first number on each item, and then sort those words
case-insensitively.

[snip]

which could also be written this way, using a trick that's come to
be
known as the Schwartzian Transform:

@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
----------------------------------------------------------------------------
This method of sorting is already built in to Ruby. The equivalent
of the above would be:

sorted = data.sort_by{ |x| x[ /\d+\s*(\S+)/, 1 ].upcase }

I wonder if it will be included in Perl 6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top