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

18 lines
315 B
Elixir
Raw Normal View History

2024-03-07 06:40:53 +00:00
defmodule RPNCalculator do
def calculate!(stack, operation) do
operation.(stack)
end
def calculate(stack, operation) do
2024-03-07 07:05:21 +00:00
{:ok, operation.(stack)}
rescue
_e -> :error
2024-03-07 06:40:53 +00:00
end
def calculate_verbose(stack, operation) do
2024-03-07 07:05:21 +00:00
{:ok, operation.(stack)}
rescue
e -> {:error, e.message}
2024-03-07 06:40:53 +00:00
end
end