22 lines
365 B
Elixir
22 lines
365 B
Elixir
|
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
|