Hi, I've started thinking about this, as maybe many of you, when I needed to stop the pipe when an error is returned. I've seen that there are different conversation about this, but I haven't clear what is the *elixir way* to handle errors using pipes.
I see two ways for achieving the same result.* The first* is to use the *pipe* *|>* and for each function catch the error and propagate it down. The error has to be always returned with the same pattern, like {:error, reason} connect |> receive_image |> resize |> rotate |> save If *receive_image* returns an error, *resize* needs to handle it def resize({:error, _}=error), do:error and to propagate it down through the pipe. So *rotate* needs to do the same, etc.. *The* *second* way I see is using the *with*, which to me seems to be more generic (and less clean) with {:ok, pid} <- connect, {:ok, image} <- receive_image(pid), {:ok, resized_image} <- resize(image), {:ok, rotated_image} <- rotate(resized_image), :ok <- save(rotated_image) do: IO.puts "saved" Now, the cool thing about *with* is that when one of the assignments fails, it exits returning the value that failed the pattern match. So, to you, what is the elixir way on handling the return errors on pipes ? Could *"with" *be seen as a new (and more generic) way of piping with error handling ? Thanks Alvise -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/1dc86df2-eca0-4fa5-b883-7b9c2df36444%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.