KeywordCalls
Documentation for KeywordCalls.
KeywordCalls.@kwalias
— Macro@kwalias f [
alpha => a
beta => b
]
declare that for the function f
, we should consider alpha
to be an alias for a
, and beta
to be an alias for b
. In a call, the names will be mapped accordingly as a pre-processing step.
KeywordCalls.@kwcall
— Macro@kwcall f(b,a,c=0)
Declares that any call f(::NamedTuple{N})
with sort(N) == (:a,:b,:c)
should be dispatched to the method already defined on f(::NamedTuple{(:b,:a,:c)})
Note that in the example @kwcall f(b,a,c=0)
, the macro checks for existence of f(::NamedTuple)
and f(; kwargs...)
methods, and only creates new ones if these don't already exist.
KeywordCalls.@kwstruct
— Macro@kwstruct Foo(b,a,c)
Equivalent to @kwcall Foo(b,a,c)
plus a definition
Foo(nt::NamedTuple{(:b, :a, :c), T}) where {T} = Foo{(:b, :a, :c), T}(nt)
Note that this assumes existence of a Foo
struct of the form
Foo{N,T} [<: SomeAbstractTypeIfYouLike]
someFieldName :: NamedTuple{N,T}
end
NOTE: Default values (as in @kwcall
) currently do not work for @kwstruct
. They can work at the REPL, but this seems to be because of a world age issue. This feature may be supported again in a future release.