January 2020
Intermediate to advanced
532 pages
13h 31m
English
Sometimes, we want to find out the parameter type within the method body. This is actually very easy to do. As it turns out, all parameters are also bound as a variable that we can access in the method body itself. The implementation of the standard eltype function provides a good example for such usage:
eltype(things::AbstractVector{T}) where {T <: Thing} = T
We can see that the type parameter T is referenced in the body. Let's how it works:

In the first call, because all objects in the array have the Spaceship type, the Spaceship type is returned, and likewise for the second call, where ...
Read now
Unlock full access