Skip to content

Commit

Permalink
Add example of initialization of Hash.push
Browse files Browse the repository at this point in the history
  • Loading branch information
ab5tract committed Jun 9, 2015
1 parent 2b7d3ce commit 2e7179a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Type/Hash.pod
Expand Up @@ -127,4 +127,16 @@ Example:
%h.push: a => [ 1 xx 3 ]; # a => [1,1,1,1,1]
%h.push: b => 3; # a => [1,1,1,1,1], b => 3
Also note that push can be used as a replacement for assignment during hash
initialization very useful ways. Take for instance the case of an inverted
index:
my %wc = 'hash' => 323, 'pair' => 322, 'pipe' => 323;
(my %inv).push: %wc.invert.unique;
say %inv; # 322 => 'pair', 323 => ['hash','pipe']
Note that such a initialization could also be written as
my %inv .= push: %wc.invert.unique;
=end pod

0 comments on commit 2e7179a

Please sign in to comment.