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

Use getproperty with field matching #18

Open
programmeroftheeve opened this issue Apr 1, 2019 · 0 comments
Open

Use getproperty with field matching #18

programmeroftheeve opened this issue Apr 1, 2019 · 0 comments

Comments

@programmeroftheeve
Copy link

Requesting an update to #3 to use getproperty instead of getfield to work with calculated fields.

Example:

struct Foo
    a::Int
end
function Base.getproperty(x::Foo, f::Symbol)
    f == :b && return getfield(x,:a) + 1
    getfield(x,f)
end

@match Foo(2) begin
    Foo(a = 1) => :a
    Foo(b = 3) => :b
end

This should return :b.

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