Skip to content

Commit d51cadd

Browse files
committed
Correct Hash types documentation, document Routine types
1 parent aa2ae69 commit d51cadd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

doc/Language/js-nutshell.pod6

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,11 @@ let todo: Map<string, boolean> = new Map([
683683
['walk the dog', true],
684684
['wash the dishes', true]
685685
]);
686+
687+
let doJob: (job: string) => boolean = function (job: string): boolean {
688+
todo.set(job, true);
689+
return true;
690+
};
686691
=end code
687692
688693
In Perl 6, variables can be typed by placing the type between the declarator
@@ -698,13 +703,19 @@ $name = Phoebe; # Throws a compile-time error
698703
# The type here defines the type of the elements of the array.
699704
my Str @hobbies = ['origami', 'playing instruments', 'programming'];
700705
701-
# The type here defines the type of the keys of the hash.
702-
# The type in the curly braces defines the type of the values of the hash.
703-
my Str %todo{Bool} = (
706+
# The type between the declarator and variable defines the type of the values
707+
# of the hash.
708+
# The type in the curly braces defines the type of the keys of the hash.
709+
my Bool %todo{Str} = (
704710
'clean the bathroom' => False,
705711
'walk the dog' => True,
706712
'wash the dishes' => True
707713
);
714+
715+
# The type here defines the return value of the routine.
716+
my Bool &do-job = sub (Str $job --> Bool) {
717+
%todo{$job} = True;
718+
};
708719
=end code
709720
710721
=head3 Comparing JavaScript and Perl 6 types

0 commit comments

Comments
 (0)