5 ms·
I wish there were a variation that can destructure more ergonomically. Instead of: ``` fetch_data() |> (fn {:ok, val, _meta} -> val :error -> "default
by manmal 2y ago
I wish there were a variation that can destructure more ergonomically.
Instead of:
```
fetch_data()
|> (fn
{:ok, val, _meta} -> val
:error -> "default value"
end).()
|> String.upcase()
```
Something like this:
```
fetch_data()
|>? {:ok, val, _meta} -> val
|>? :error -> "default value"
|> String.upcase()
```
- smallerize 2y agofetch_data() |> case do {:ok, val, _meta} -> val :error -> "default value" end You have the extra "case do...end" block but it's pretty close? This is for sequential conditions. If you have nested conditions, check out a where block instead. https://dev.to/martinthenth/using-elixirs-with-statement-5e36#3-chained-functions-in-with-statements https://dev.to/martinthenth/using-elixirs-with-statement-5e3...
- manmal 2y agoThanks, that looks good!
- deleted 2y ago[deleted]