Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeywordDispatch analogue to @kwdef #12

Open
yygrechka opened this issue Jan 8, 2021 · 0 comments
Open

KeywordDispatch analogue to @kwdef #12

yygrechka opened this issue Jan 8, 2021 · 0 comments

Comments

@yygrechka
Copy link

I'm relatively new to Julia, and I wanted keyword constructors, which led me to the Base.@kwdef macro

However, this macro does not allow keyword dispatch, which led me to this package.

With KeywordDispatch, I can do something like this:

struct Bar
    a::Int
    b::String
end

@kwdispatch Bar()

@kwmethod Bar(;a, b) = Bar(a,b)
@kwmethod Bar(;a) = Bar(a=a, b="1")

It would be useful to have an analogous macro to @kwdef that will automatically define this first constructor:

@kwmethod Bar(;a, b) = Bar(a,b)

If this is already implemented, I'd appreciate a pointer as to how this is done.

@yygrechka yygrechka changed the title KeywordDispatch version of @kwdef KeywordDispatch analogue to @kwdef Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant