Case statement on one line

Is there a way to put an entire case statement on one line? I tried doing something like this:

case number of (5 -> "five") (_ -> "unknown")

But it gives syntax error

no. Elm is whitespace sensitive and case of need a line break.
What you can do is define a function isFive and hide the case distinction in there.

Elm does allow having each case as one line though:

case number of
  5 -> "five"
  _ -> "unknown"

However it’s currently not supported by elm-format.

Also, functions like Maybe.Extra.unwrap and Result.Extra.unwrap can be quite useful for oneliners.

Seems like this is the best I can do

( \v -> case v of
    Item a -> Just a
    _ -> Nothing )

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.