Created
October 18, 2018 19:02
-
-
Save veverkap/3c050112701cb6f67a8403347db6afeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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