Revision 26182
- Date:
- 2009/04/10 19:26:13
- Files:
Legend:
- Added
- Removed
- Modified
-
docs/Perl6/Spec/S32-setting-library/Containers.pod
15 15 Moritz Lenz <moritz@faui2k3.org> 16 16 Tim Nelson <wayland@wayland.id.au> 17 17 Date: 19 Feb 2009 extracted from S29-functions.pod 18 Last Modified: 8 Apr 2009 19 Version: 4 18 Last Modified: 10 Apr 2009 19 Version: 5 20 20 21 21 The document is a draft. 22 22 … … 636 636 Returns a junction which will only match against another value if none of 637 637 the keys in the hash matches. 638 638 639 =item reverse 639 =item invert 640 640 641 our List multi method reverse ( %hash: ) is export { 641 our List multi method invert ( %hash: ) is export { 642 642 map -> $k, $v { $v X=> $k }, %hash.kv; 643 643 } 644 644 … … 653 653 Like hash assignment insofar as it accepts either C<Pair> objects or 654 654 alternating keys and values; however, unlike assignment, when 655 655 a duplicate key is detected, coerces the colliding entry's value to an 656 array and pushes the Pair's value onto that array. Hence to reverse 656 array and pushes the Pair's value onto that array. Hence to invert 657 657 a hash containing duplicate values without losing (associative) information, 658 658 say: 659 659 660 %out.push(%in.reverse) 660 %out.push(%in.invert) 661 661 662 662 Note that when reading the values of such a hash, you must not assume 663 663 that all the elements are arrays, since the first instance of a key … … 703 703 704 704 class Pair does Associative {...} 705 705 706 =item reverse 706 =item invert 707 707 708 our List multi method reverse ( $pair: ) is export { 708 our List multi method invert ( $pair: ) is export { 709 709 $pair.value X=> $pair.key 710 710 } 711 711