Why do tuples exist?

Here’s what i mean:

with {:ok, object_1} <- operation_1(),
     {:ok, object_2} <- operation_2(object_1) do
  final_operation(object_2)
end

If all pattern matching goes ok, the result of final_operation/1 is returned. If any of the others fail, you get the certainty that with will return {:error, some_error} as long as all functions have the same type of return.

2 Likes