Is it possible to capture all the arguments and pass it to another function?
To make code like that shorter:
function send_binary(;
binary_hash::String,
binary::String
)::Any
post_json(
"http://localhost:$(port)/v1/binaries",
json((binary_hash=binary_hash, binary=binary))
)
end
(theoretical) Shorter version:
function send_binary(;
binary_hash::String,
binary::String
)::Any
post_json("http://localhost:$(port)/v1/binaries", json(arguments))
end
The splat operator captures arguments in function definitions and interpolates arguments in function calls:
julia> bar(; a=0, b=0) = a, b
bar (generic function with 1 method)
julia> foo(; kwargs...) = bar(; kwargs...)
foo (generic function with 1 method)
julia> foo(; a=1, b=2)
(1, 2)
julia> foo()
(0, 0)
julia> foo(; b=1)
(0, 1)
Your example can be written as:
function send_binary(; kwargs...)
return post_json("http://localhost:$(port)/v1/binaries", json(; kwargs....))
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With