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

documentation for active patterns (@active) is out-of-date while deprecation warning is up-to-date #143

Open
thautwarm opened this issue Jul 30, 2022 · 1 comment

Comments

@thautwarm
Copy link
Owner

Simple active pattern implementation.
You can give a qualifier in the first argument of `@active` to customize its visibility in other modules.
```julia
@active F(x) begin
if x > 0
nothing
else
:ok
end
end
@match -1 begin
F(:ok) => false
_ => true
end # true
@active public IsEven(x) begin
x % 2 === 0
end
@match 4 begin
IsEven() => :ok
_ => :err
end # :ok
```
"""
macro active(qualifier, case, active_body)
deprecate_qualifier_macro(qualifier, __source__)
active_def(case, active_body, __module__, __source__) |> esc
end

@thautwarm
Copy link
Owner Author

julia> @active F(x) begin
                if x > 0
                    nothing
                else
                    :ok
                end
            end

julia>

julia>  @match -1 begin
                F(:ok) => false
                _ => true
            end # true
ERROR: invalid use of active patterns: 1-ary view pattern(F(x)) should accept Union{Some{T}, Nothing} instead of Union{T, Nothing}! A simple solution is:
  (@active F(x) ex) =>
  (@active F(x) let r=ex; r === nothing? r : Some(r)) end

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