Skip to content

simonbyrne/KeywordDispatch.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KeywordDispatch.jl

Build Status Code Coverage

Dispatch on keyword arguments. It exports 2 macros:

  • @kwdispatch designates a function signature to use for keyword dispatch
  • @kwmethod defines the method for the keyword argument

Example

using KeywordDispatch

@kwdispatch f()

@kwmethod f(;a) = "a is $a"
@kwmethod f(;a::Integer) = "a is $a, and is an Integer"
@kwmethod f(;b) = "b is $b"
@kwmethod f(;a,b) = "a is $a, b is $b"
@kwmethod f(;) = "look mum, no args!"

at the REPL:

julia> f()
"look mum, no args!"

julia> f(a=1.0)
"a is 1.0"

julia> f(a=1)
"a is 1, and is an Integer"

julia> f(b=3,a=1)
"a is 1, b is 3"

About

Dispatch on keyword arguments

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages