Skip to content

Commit

Permalink
add Pair.exchange as distinct from .invert
Browse files Browse the repository at this point in the history
  • Loading branch information
TimToady committed Feb 27, 2015
1 parent 4198be6 commit 582cee8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions S32-setting-library/Containers.pod
Expand Up @@ -1068,7 +1068,7 @@ merely sets the value without turning it into an array. (Fortunately,
most list operators create a list of one element when used on an object
that is not a list.)

The intent is that reversing a hash twice produces a hash equivalent
The intent is that inverting a hash twice produces a hash equivalent
to the original hash.

=back
Expand Down Expand Up @@ -1205,12 +1205,26 @@ to C<Pair> unless you try to modify it.)

=over

=item exchange

multi method exchange ( $pair: --> List ) is export {
$pair.value => $pair.key
}

Returns new pair with key and value swapped.

=item invert

multi method invert ( $pair: --> List ) is export {
$pair.value X=> $pair.key
$pair.value »=>» $pair.key
}

Note that this is not a simple exchange, but splits pairs with C<Positional> values
into multiple pairs in support of database inversion operations (when
used along with C<Hash.push>).

Equivalent to C<exchange> if no values are C<Positional>.

=back

=head2 EnumMap
Expand Down Expand Up @@ -1479,3 +1493,4 @@ discourage casual use of the eigenstates as a set.)
Moritz Lenz <moritz@faui2k3.org>
Tim Nelson <wayland@wayland.id.au>

=for vim:set expandtab sw=4:

0 comments on commit 582cee8

Please sign in to comment.