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

allow _ as the fallback 'wildcard' case #56

Merged
merged 4 commits into from
Nov 20, 2023
Merged

Conversation

MasonProtter
Copy link
Owner

Closes #55

With this change, we can now do

julia> is_apple(f::Fruit) = @cases f begin
           apple => true
           _ => false
       end
is_apple (generic function with 1 method)

julia> is_apple(apple)
true

julia> is_apple(mango)
false
julia> code_typed(is_apple, Tuple{Fruit})
1-element Vector{Any}:
 CodeInfo(
1%1 = (getfield)(f, :data)::Union{SumTypes.Variant{:apple, (), Tuple{}}, SumTypes.Variant{:banana, (), Tuple{}}, SumTypes.Variant{:orange, (), Tuple{}}, SumTypes.Variant{:kiwi, (), Tuple{}}, SumTypes.Variant{:pear, (), Tuple{}}, SumTypes.Variant{:mango, (), Tuple{}}}%2 = (%1 isa SumTypes.Variant{:apple})::Bool
└──      goto #3 if not %2
2return true
3return false
) => Bool

Copy link

codecov bot commented Nov 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (003c9d4) 100.00% compared to head (c6e15fc) 100.00%.

❗ Current head c6e15fc differs from pull request most recent head 9541e58. Consider uploading reports for the commit 9541e58 to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #56   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          249       260   +11     
=========================================
+ Hits           249       260   +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MasonProtter MasonProtter merged commit 8cf1b49 into master Nov 20, 2023
@MasonProtter MasonProtter deleted the fallback-case branch November 20, 2023 17:48
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

Successfully merging this pull request may close these issues.

default in @cases when unpacking is not necessary
1 participant