Skip to content

Instantly share code, notes, and snippets.

View willgeorgetaylor's full-sized avatar
⚒️
Busy at the moment

Will Taylor willgeorgetaylor

⚒️
Busy at the moment
View GitHub Profile
@willgeorgetaylor
willgeorgetaylor / guard_pipe.ex
Last active January 18, 2024 10:23
Elixir GuardPipe macro
defmodule Utils.GuardPipe do
@moduledoc ~S"""
When a value input into the pipe is an error tuple, the subsequent function in the pipeline will not execute, and the error tuple is immediately returned as the output.
Example:
iex> {:error, 9} ~> Kernel.+(1)
{:error, 9}
On the other hand, if the input is an `ok` tuple, its inner value is extracted and passed on to the next function in the pipeline. The final output of the pipe will be either an `ok` or an `error` tuple.