F#, Pipe forward a match case without using temp variable
Similar to the question above, is there a way to pipe-forward a variable to a match case without using a temp variable or a lambda?
The idea:
let temp =
x
|> Function1
|> Function2
// ........ Many functions later.
|> FunctionN
in
result =
case temp of
Case1 -> "Output 1"
Case2 -> "Output 2"
_ -> "Other Output"
I hope to achieve the following:
result =
x
|> Function1
|> Function2
// ........ Many functions later.
|> FunctionN
|> case of // Syntax Error! Should use "case temp of"
Case1 -> "Output 1"
Case2 -> "Output 2"
_ -> "Other Output"
I can use a lambda function, but I would still be "naming" the temp variable.
result =
x
|> Function1
|> Function2
// ........ Many functions later.
|> FunctionN
|> \temp -> case temp of
Case1 -> "Output 1"
Case2 -> "Output 2"
_ -> "Other Output"
Is there a way in the Elm syntax to "get rid" of the temp variable? Thanks.
No, Elm does not have that ability.
Other languages like Haskell allow something similar via the LambdaCase
extension, but Elm tends to avoid having too many ways to say the same thing, erring on the side of keeping syntax simple.
The issue has been raised before, and Elm's author rejected the proposal with the following comment:
More generally though, the focus right now is not on growing the syntax of Elm. (We're actually dropping stuff more often.) If something can be expressed in Elm already, I'm not hugely interested in providing alternate ways to express it. In this case, I think we would be adding syntax to make things less regular and harder to read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With