I want to learn some basics of this great langauge. I have put this code together:
defmodule Xe do
def call(input) do
with {:ok, first} when is_integer(input) <- by_ten(input),
{:ok, second} <- by_five(first)
do
IO.puts second
else
_ ->
IO.puts "error"
end
end
def by_ten(input) do
{:ok, input * 10}
end
def by_five(input) do
{:ok, input * 5}
end
end
Xe.call("abc")
Here I am getting:
(ArithmeticError) bad argument in arithmetic expression
a.ex:16: Xe.by_ten/1
a.ex:5: Xe.call/1
(elixir) lib/code.ex:677: Code.require_file/2
How to avoid this using guards? Thank you.






















