Edit: Thank you @kristoffer.carlsson for pointing out my oversight and the code is working now.
# I forgot the `( )`. Fixed now
dict = Dict{Any, Any}()
# The doc example
get!(dict, :a) do
time()
end
# The equivalent
get!( ()-> time(), dict, :b)
# If you already have function
function f()
return time()
end
get!(f, dict, :c)
println(duct) # Dict{Any,Any}(:a => 1.593679792519603e9,:b => 1.59367979306765e9,:c => 1.59367992264622e9)
My original post:
AFAIK,
-
doblock in Julia replaces the first parameter (f::Function) ofget!(). Usedoblock if the function is more than a one-liner, for readability. -
time()is to give a value to each element indict. It can be anything as you see fit.
So it is equivalent to
get!(x-> time(), dict, key)