Skip to content

Commit 2f8a1c1

Browse files
committed
Document trap on set subroutines on Associative
Fixes rakudo/rakudo#2604
1 parent 18b3e10 commit 2f8a1c1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

doc/Language/traps.pod6

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ Alternatively, you can also use the L<concatenation operator|/routine/~> instead
152152
sub count-it { say "Count is " ~ $++ }
153153
=end code
154154
155+
=head2 Using set subroutines on Associative when the value is falsey
156+
157+
Using L<(cont)|/routine/(cont)>, L<∋|/routine/∋>, L<∌|/routine/∌>,
158+
L<(elem)|/routine/(elem)>, L<∈|/routine/∈>, or L<∉|/routine/∉> on classes
159+
implementing L<Associative|/type/Associative> will return C<False> if the value
160+
of the key is falsey:
161+
162+
=begin code
163+
enum Foo «a b»;
164+
say Foo.enums ∋ 'a';
165+
166+
# OUTPUT:
167+
# False
168+
=end code
169+
170+
Instead, use C<:exists>:
171+
172+
=begin code
173+
enum Foo «a b»;
174+
say Foo.enums<a>:exists;
175+
176+
# OUTPUT:
177+
# True
178+
=end code
179+
155180
=head1 Blocks
156181
157182
=head2 Beware of empty "blocks"

0 commit comments

Comments
 (0)