Case expression function #1271
edongashi
started this conversation in
Ideas & suggestions
Replies: 1 comment 5 replies
-
Hi @edongashi ! Thanks for the proposal. I would also expect this syntax to work outside of pipelines so things like this can be done: let is_empty = case _ {
[] -> True
_ -> False
} I am quite interested in what other community members think of this. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently
case
expressions require an immediately evaluated argument:A proposed
case _
syntax would allow declaring a pattern matching function similar to F#'sfunction
keyword:Which currently has to be written as:
You can also inject the
case
function into pipelines:I have found that "piping into" case expressions is not uncommon in Elixir. Most uses I noticed have been for error handling, but there was also a significant usage for matching lists evaluated from some pipeline. I imagine union case matching will also be common in gleam.
The contrived example below shows how we would handle a result containing a list of items.
Rewriting the above with
result.map_*
higher order functions becomes rather verbose:Beta Was this translation helpful? Give feedback.
All reactions