September 2017
Beginner
402 pages
9h 52m
English
Now, as we have used code blocks with sort, grep, map, and reduce, it's time to use the so-called WhateverCode type in Perl 6. It involves the (*) star and creates a code block that can be used as any code block that we used earlier.
For example, instead of {.uc} you can write *.uc. The following two lines of code are equivalent:
say map {.uc}, 'a'..'d'; # (A B C D)say map *.uc, 'a'..'d'; # (A B C D)
Similarly, this is how the WhateverCode block can be used to replace anonymous code block in the examples with grep and sort:
say grep * > 10, 1..15; # (11 12 13 14 15)say sort * <=> *, <11 12 10 13 15 14>; # (10 11 12 13 14 15)
In the second example, there are two stars, which corresponds to the $^a and $^b placeholder ...
Read now
Unlock full access