File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -683,6 +683,11 @@ let todo: Map<string, boolean> = new Map([
683
683
['walk the dog', true],
684
684
['wash the dishes', true]
685
685
]);
686
+
687
+ let doJob: (job: string) => boolean = function (job: string): boolean {
688
+ todo.set(job, true);
689
+ return true;
690
+ };
686
691
= end code
687
692
688
693
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
698
703
# The type here defines the type of the elements of the array.
699
704
my Str @hobbies = ['origami', 'playing instruments', 'programming'];
700
705
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} = (
704
710
'clean the bathroom' => False,
705
711
'walk the dog' => True,
706
712
'wash the dishes' => True
707
713
);
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
+ };
708
719
= end code
709
720
710
721
= head3 Comparing JavaScript and Perl 6 types
You can’t perform that action at this time.
0 commit comments