Skip to content

Instantly share code, notes, and snippets.

@veverkap
Created October 18, 2018 19:02
Show Gist options
  • Save veverkap/3c050112701cb6f67a8403347db6afeb to your computer and use it in GitHub Desktop.
Save veverkap/3c050112701cb6f67a8403347db6afeb to your computer and use it in GitHub Desktop.
defmodule Tester do
def run(input) do
with {:ok, widget} <- process_widget(input) do
do_something_with_widget(widget) #noop
else
{:error, reason} ->
#something with reason
end
@spec process_widget(input :: binary) :: {:ok, contents :: binary} | {:error, reason :: binary}
def process_widget(input) do
with {:ok, contents} <- File.read(input),
{:ok, decoded} <- Jason.decode(contents) do
{:ok, decoded}
else
error ->
{:error, "Received error"}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment