Initial upload
This commit is contained in:
21
elixir/rpn-calculator/lib/rpn_calculator.ex
Normal file
21
elixir/rpn-calculator/lib/rpn_calculator.ex
Normal file
@@ -0,0 +1,21 @@
|
||||
defmodule RPNCalculator do
|
||||
def calculate!(stack, operation) do
|
||||
operation.(stack)
|
||||
end
|
||||
|
||||
def calculate(stack, operation) do
|
||||
try do
|
||||
{:ok, operation.(stack)}
|
||||
rescue
|
||||
_ in RuntimeError -> :error
|
||||
end
|
||||
end
|
||||
|
||||
def calculate_verbose(stack, operation) do
|
||||
try do
|
||||
{:ok, operation.(stack)}
|
||||
rescue
|
||||
e in ArgumentError -> {:error, e.message}
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user