Skip to content

Use getproperty with field matching #18

Open
@programmeroftheeve

Description

@programmeroftheeve

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions