Is it possible to have guards on lambda functions?
For example:
\k
| k < 0 -> "negative"
| k == 0 -> "zero"
| otherwise -> "positive"
Is it possible to have guards on lambda functions?
For example:
\k
| k < 0 -> "negative"
| k == 0 -> "zero"
| otherwise -> "positive"
Yet another way uses a combination of the LambdaCase and ViewPatterns GHC extensions:
{-# LANGUAGE LambdaCase, ViewPatterns #-}
\case
((< 0) -> True) -> "negative"
((==0) -> True) -> "zero"
_ -> "positive"
This keeps you from having to name an intermediate variable.