-
-
Save petros/7cbaacb697de6a52c1931703dd92039e to your computer and use it in GitHub Desktop.
RPN Calculator - Elixir - Exercism
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 RPNCalculator do | |
@spec calculate!(list(), Function.t()) :: :ok | |
def calculate!(_stack, operation) do | |
operation.(1) | |
end | |
@spec calculate(list(), Function.t()) :: {:ok, String.t()} | :error | |
def calculate(_stack, operation) do | |
try do | |
operation.(1) | |
{:ok, "operation completed"} | |
rescue | |
_ -> :error | |
end | |
end | |
@spec calculate_verbose(list(), Function.t()) :: {:ok | :error, String.t()} | |
def calculate_verbose(_stack, operation) do | |
try do | |
operation.(1) | |
{:ok, "operation completed"} | |
rescue | |
e in ArgumentError -> {:error, e.message} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment