4 ms·
with {:step_1, {:ok, value}} <- {:step_1, fn_call(...)} I also use this pattern a lot :) To be fair, I'm not using this library everywhere. Only when case/wit
by linkdd 5y ago
with {:step_1, {:ok, value}} <- {:step_1, fn_call(...)}
I also use this pattern a lot :)
To be fair, I'm not using this library everywhere. Only when case/with become hard to read.
Or when I have a pipeline like:
fetch_list_of_resources()
|> Result.or_else(fn _ -> [] end) # ignore the error
|> Stream.filter(&check_condition/1)
|> Stream.map(&delete_resource/1)
|> Result.collect() # fails at the first error
|> Result.unwrap!() # raise if error ASAP
|> Enum.map(&log_deleted_resource/1)
It is IMHO easier to read, refactor and debug (with some well-placed IO.inspect).
Before this library, I was copy/pasting `then(fn ... end)`. I don't like to repeat myself :)