mirror of
https://github.com/rjNemo/exercism-elixir
synced 2026-06-06 02:16:48 +00:00
19 lines
411 B
Elixir
19 lines
411 B
Elixir
defmodule RPNCalculator do
|
|
def calculate!(stack, operation), do: operation.(stack)
|
|
|
|
def calculate(stack, operation) do
|
|
try do
|
|
{:ok, calculate!(stack, operation)}
|
|
rescue
|
|
_ in RuntimeError -> :error
|
|
end
|
|
end
|
|
|
|
def calculate_verbose(stack, operation) do
|
|
try do
|
|
{:ok, calculate!(stack, operation)}
|
|
rescue
|
|
e in ArgumentError -> {:error, e.message}
|
|
end
|
|
end
|
|
end
|