exercism/elixir/rpn-calculator/lib/rpn_calculator.ex

18 lines
315 B
Elixir

defmodule RPNCalculator do
def calculate!(stack, operation) do
operation.(stack)
end
def calculate(stack, operation) do
{:ok, operation.(stack)}
rescue
_e -> :error
end
def calculate_verbose(stack, operation) do
{:ok, operation.(stack)}
rescue
e -> {:error, e.message}
end
end