Skip to content

Instantly share code, notes, and snippets.

@YannickFricke
Created July 18, 2024 15:29
Show Gist options
  • Save YannickFricke/fe1f9afde8125fe07168be8a186a4f55 to your computer and use it in GitHub Desktop.
Save YannickFricke/fe1f9afde8125fe07168be8a186a4f55 to your computer and use it in GitHub Desktop.
Phoenix Utility methods
defmodule Utils do
@moduledoc """
## Usage
Could be imported in <project>/lib/my_app_web.ex for general access.
For example in controller/0
```elixir
import Utils
def fancy_function() do
"input"
|> String.split("")
|> Enum.join()
|> noreply()
end
```
"""
@spec ok(value :: term()) :: {:ok, term()}
def ok(value), do: {:ok, value}
@spec error(value :: term()) :: {:error, term()}
def error(value), do: {:error, value}
@spec noreply(value :: term()) :: {:noreply, term()}
def noreply(value), do: {:noreply, value}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment