January 2020
Intermediate to advanced
532 pages
13h 31m
English
When defining functions, we have an option to annotate each argument with type information. The type of an argument can be a regular abstract type, concrete type, or a parametric type. Let's consider this sample function for exploding an array of game pieces:
# explode an array of objectsfunction explode(things::AbstractVector{Any}) for t in things println("Exploding ", t) endend
The things argument is annotated with AbstractVector{Any}, which means that it can be any AbstractVector type that contains any object that is a subtype of Any (which is really just everything). To make the method parametric, we can just rewrite it with a T type parameter as follows:
# explode an array of objects (parametric version)function ...
Read now
Unlock full access