Hi everyone,
Can someone help me out wit the following issue? I am trying to use the Enum.reduce function as follows:
Enum.reduce(items, Decimal.new(0), fn(i, acc) ->
if i.tax == false do
Decimal.mult(Decimal.new(i.qty), Decimal.new(i.unit_price))
|> Decimal.add(Decimal.new(acc))
end
end)
The problem is that the acc is “nil” so the add function returns error because it was un able to convert “nil” to decimal.
Any suggestions why is the accumulator not been initialized to 0.
Thanks.