rpn_calculator v2
This commit is contained in:
parent
d1b894006c
commit
7ae168f5ea
|
@ -4,18 +4,14 @@ defmodule RPNCalculator do
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate(stack, operation) do
|
def calculate(stack, operation) do
|
||||||
try do
|
|
||||||
{:ok, operation.(stack)}
|
{:ok, operation.(stack)}
|
||||||
rescue
|
rescue
|
||||||
_e -> :error
|
_e -> :error
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def calculate_verbose(stack, operation) do
|
def calculate_verbose(stack, operation) do
|
||||||
try do
|
|
||||||
{:ok, operation.(stack)}
|
{:ok, operation.(stack)}
|
||||||
rescue
|
rescue
|
||||||
e -> {:error, e.message}
|
e -> {:error, e.message}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue