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

22 lines
365 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
try do
{:ok, operation.(stack)}
rescue
_e -> :error
end
end
def calculate_verbose(stack, operation) do
try do
{:ok, operation.(stack)}
rescue
e -> {:error, e.message}
end
end
end