@@ -8,8 +8,8 @@ DRAFT: Synopsis 32: Setting Library - Containers.pod
8
8
9
9
Created: 19 Feb 2009 extracted from S29-functions.pod
10
10
11
- Last Modified: 26 Oct 2014
12
- Version: 48
11
+ Last Modified: 26 Feb 2015
12
+ Version: 49
13
13
14
14
=head1 Function Roles
15
15
@@ -681,6 +681,38 @@ are converted to a list of individual values before permuting them.)
681
681
682
682
The functional form assumes it is working on a list of integers C<^$n>.
683
683
684
+ =item pairup
685
+
686
+ multi method pairup ( )
687
+
688
+ Turns a list of mixed keys, values, and pairs into a list of pairs in
689
+ the same way that a hash composer does, only without creating the hash.
690
+ While there is more list to process, the next value is examined. If it
691
+ is a Pair, it is passed through unchanged. Otherwise a second value is
692
+ also taken from the list and those two values together are turned into
693
+ a pair. It is an X::Pairup::OddNumber error if there is no next value.
694
+ (It is not an error if the second value happens be a pair; if so, it
695
+ merely becomes the value paired with the key of the first value.)
696
+
697
+ Obviously you cannot create pairs where the keys are Pairs using this
698
+ function. Use a map or some such for that.
699
+
700
+ =item invert
701
+
702
+ multi method invert ( --> List ) is export {
703
+ self.map: -> $p { $.value X=> $.key }
704
+ }
705
+
706
+ Produces a backmapping of values to keys, expanding list values
707
+ into multiple pairs. (The C<< X=> >> expands C<$v> if it is a list.)
708
+ To handle keys that do C<Positional> you'll need to write your own map.
709
+
710
+ The invocant must be a list containing only Pairs, and throws an error if
711
+ anything that is not a Pair is passed. To get combine kv values, use
712
+ C<.pairup> first:
713
+
714
+ @kv.pairup.invert
715
+
684
716
=back
685
717
686
718
=head2 Array
@@ -1013,7 +1045,7 @@ the keys in the hash matches.
1013
1045
1014
1046
Produces a backmapping of values to keys, expanding list values
1015
1047
into multiple pairs. (The C<< X=> >> expands C<$v> if it is a list.)
1016
- [NB: this may need refinement to handle keys that do C<Positional>.]
1048
+ To handle keys that do C<Positional> you'll need to write your own map.
1017
1049
1018
1050
=item push
1019
1051
0 commit comments