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

default in @cases when unpacking is not necessary #55

Closed
Krastanov opened this issue Nov 20, 2023 · 5 comments · Fixed by #56
Closed

default in @cases when unpacking is not necessary #55

Krastanov opened this issue Nov 20, 2023 · 5 comments · Fixed by #56

Comments

@Krastanov
Copy link

I have a situation in which a sumtype instance will be passing through "filters", where they are either "consumed" if they are a specific particular variant or passed on to the next "filter".

Is an additional "default" option possible, as discussed in #31 ?

Opening a new issue, because I have the impression the conversation in 31 was focused on default with unpacking

@MasonProtter
Copy link
Owner

Is it enough to just write something like

@sum_type Fruit begin
    apple
    banana
    orange
    kiwi
    pear
    mango
end

is_apple(f::Fruit) = @cases f begin
    apple => true
    [banana, orange, kiwi, pear, mango] => false 
end

?

@Krastanov
Copy link
Author

The list of possible variants is much too long for the situation I am dealing with. Admittedly, maybe that is code smell and I should use a different approach. Independently of that though, is that a feature that makes sense to be added?

@MasonProtter
Copy link
Owner

Should now work with #56! Will be released as version 0.5.1 and available on the General registry once this finishes: JuliaRegistries/General#95659

@Krastanov
Copy link
Author

Wow, that was amazingly quick! Thank you, it is much appreciated!

@MasonProtter
Copy link
Owner

Happy to help!

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 a pull request may close this issue.

2 participants