Skip to content

Commit 4356fbf

Browse files
committed
Clarify Callable requirement
1 parent 51a6853 commit 4356fbf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doc/Type/Callable.pod6

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ container, is has to implement Callable.
4141
my &a = A;
4242
say a(); # OUTPUT: «called␤»
4343
44+
Applying the Callable role is not a requirement, however, should a class simply want to add subroutine-like semantics in a regular scalar container.
45+
46+
class A {
47+
has @.values;
48+
submethod CALL-ME(Int $x where 0 <= * < @!values.elems) {
49+
@!values[$x]
50+
}
51+
}
52+
my $a = A.new: values => [4,5,6,7]
53+
say $a(2); # OUTPUT: «6␤»
54+
4455
=head2 method Capture
4556
4657
Defined as:
@@ -51,4 +62,4 @@ Throws C<X::Cannot::Capture>.
5162
5263
=end pod
5364

54-
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
65+
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)