Skip to content

Commit

Permalink
Add example for SetHash initialization.
Browse files Browse the repository at this point in the history
See issue #1939
  • Loading branch information
fluca1978 committed May 2, 2018
1 parent fc9df1c commit 1d95b42
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/Type/SetHash.pod6
Expand Up @@ -66,6 +66,15 @@ the set - and keys mapped to values which boolify to C<False> are skipped:
say $n.keys.perl; # OUTPUT: «("one", "two").Seq␤»
say $n.keys.map(&WHAT); # OUTPUT: «((Str) (Str))␤»
It is also possible to initialize a single key with the use of C<{}>:
my $sh = SetHash.new;
$sh{ 'key1' } = True;
$sh{ 'key2' } = 'Hello World!';
$sh{ 'key3' } = 0; # does not store the key since 0.Bool is False
say $sh; # OUTPUT: «SetHash(key1 key2)␤»
say $sh.keys.perl; # OUTPUT: «("key1", "key2").Seq␤»
=head1 Operators
Perl 6 provides common set operators, which can take C<SetHash>es (or any other
Expand Down

1 comment on commit 1d95b42

@lizmat
Copy link
Collaborator

@lizmat lizmat commented on 1d95b42 May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the keys are strings, then you can also use $sh<key1>. Not sure if that makes sense in the context of a Set though, as a Set will take anything as a key and not just strings.

Please sign in to comment.