January 2020
Intermediate to advanced
532 pages
13h 31m
English
Now that we can tell which types are liquid and which are not, we can define methods that take objects with those traits. First, let's do something really simple:
# The thing is tradable if it is liquidtradable(x::T) where {T} = tradable(LiquidityStyle(T), x)tradable(::IsLiquid, x) = truetradable(::IsIlliquid, x) = false
In Julia, types are first-class citizens. The tradable(x::T) where {T} signature captures the type of argument as T. Since we have already defined the LiquidityStyle function, we can derive whether the passed argument exhibits the IsLiquid or IsIlliquid trait. So, the first tradable method simply takes the return value of LiquidityStyle(T) and passes it as the first argument for the other two ...
Read now
Unlock full access