Skip to content

Commit

Permalink
Correct Hash types documentation, document Routine types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiepi committed Mar 12, 2019
1 parent aa2ae69 commit d51cadd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions doc/Language/js-nutshell.pod6
Expand Up @@ -683,6 +683,11 @@ let todo: Map<string, boolean> = new Map([
['walk the dog', true],
['wash the dishes', true]
]);
let doJob: (job: string) => boolean = function (job: string): boolean {
todo.set(job, true);
return true;
};
=end code
In Perl 6, variables can be typed by placing the type between the declarator
Expand All @@ -698,13 +703,19 @@ $name = Phoebe; # Throws a compile-time error
# The type here defines the type of the elements of the array.
my Str @hobbies = ['origami', 'playing instruments', 'programming'];
# The type here defines the type of the keys of the hash.
# The type in the curly braces defines the type of the values of the hash.
my Str %todo{Bool} = (
# The type between the declarator and variable defines the type of the values
# of the hash.
# The type in the curly braces defines the type of the keys of the hash.
my Bool %todo{Str} = (
'clean the bathroom' => False,
'walk the dog' => True,
'wash the dishes' => True
);
# The type here defines the return value of the routine.
my Bool &do-job = sub (Str $job --> Bool) {
%todo{$job} = True;
};
=end code
=head3 Comparing JavaScript and Perl 6 types
Expand Down

0 comments on commit d51cadd

Please sign in to comment.