@@ -2490,38 +2490,46 @@ case of routines/methods that take a single argument or where the first argument
2490
2490
is a block, it's often required that you call with parentheses (though this
2491
2491
is not required for the very last routine/method).
2492
2492
2493
- # Traditional structure, read bottom-to-top
2494
- my @result =
2495
- sort # (4) Sort, result is <Earth People>
2496
- grep { /<[PE]>/ }, # (3) Look for P or E
2497
- map { .tc }, # (2) Capitalize the words
2498
- <people of earth>; # (1) Start with the input
2493
+ This "traditional" structure, read bottom-to-top, with the last two
2494
+ lines creating the data structure that is going to be processed
2495
+
2496
+ my @fractions = <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS>;
2497
+ my @result = map { .uniparse }, # (3) Converts to unicode
2498
+ grep { .uniparse }, # (2) Checks if it parses
2499
+ map( {"VULGAR FRACTION " ~ $^þ }, @fractions); # (1) Adds string to input
2500
+
2501
+ # @result is [⅖ ⅗ ⅜ ⅘ ⅚ ⅝ ⅞]
2502
+
2503
+ Now we use the feed operator (left-to-right) with parentheses, read top-to-bottom
2499
2504
2500
- # Feed (left-to-right) with parentheses, read top-to-bottom
2501
2505
my @result = (
2502
- <people of earth> # (1) Start with the input
2503
- ==> map({ .tc } ) # (2) Capitalize the words
2504
- ==> grep /<[PE]>/ # (3) Look for P or E
2505
- ==> sort # (4) Sort, result is <Earth People>
2506
+ <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS> # (1) Input
2507
+ ==> map( {"VULGAR FRACTION " ~ $^þ } ) # (2) Converts to Unicode name
2508
+ ==> grep({ .uniparse }) # (3) Filters only real names
2509
+ ==> map( { .uniparse} ); # (4) Converts to unicode
2506
2510
);
2507
2511
2508
- # For illustration, method chaining equivalent, read top-to-bottom
2509
- my @result =
2510
- <people of earth> # (1) Start with the input
2511
- .map({ .tc }) # (2) Capitalize the words
2512
- .grep(/<[PE]>/) # (3) Look for P or E
2513
- .sort; # (4) Sort, result is <Earth People>
2512
+ For illustration, method chaining equivalent, read top-to-bottom, using the same sequence as above
2513
+
2514
+ my @result = ( <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS>)
2515
+ .map( {"VULGAR FRACTION " ~ $^þ } )
2516
+ .grep({ .uniparse })
2517
+ .map({ .uniparse });
2514
2518
2515
- # To assign without the need of parentheses use another feed operator
2519
+ Although in this particular case the result is the same, the feed operator C « ==> » more clearly
2520
+ shows intent with arrow pointing the data flow. To assign without
2521
+ the need of parentheses use another feed operator
2522
+
2516
2523
my @result;
2517
2524
<people of earth>
2518
2525
==> map({ .tc })
2519
2526
==> grep /<[PE]>/
2520
2527
==> sort()
2521
2528
==> @result;
2522
2529
2523
- # It can be useful to capture a partial result, however, unlike
2524
- # the leftward feed operator, it does require parentheses or a semicolon
2530
+ It can be useful to capture a partial result, however, unlike the
2531
+ leftward feed operator, it does require parentheses or a semicolon
2532
+
2525
2533
my @result;
2526
2534
<people of earth>
2527
2535
==> map({ .tc })
0 commit comments