Is there a way to get the expr of case?

To be more specific, the situation is like this

value
|> some_transformation
|> case do
    ^pattern ->  # can i get what was piped into case here? 
    _ ->
end

Whatever the value of pattern is, it is identical with whatever was piped into the case/2.

1 Like

Yeah, as always, first ask and then the solution comes to your mind a few minutes later.
You idea won’t work in the _ -> clause though.
what I did was:

value
|> some_transformation
|> case do
    ^pattern ->  do_something pattern
    _ = b -> do_otherthing b
end

it still requires an additional variable, but at list its local and not leaking. So it is fine )

You didn’t ask for the fall through clause, but the first one only :smile_cat: For the fall through clause, simply writing b -> is equivalent.

3 Likes