Feature Request - Decimal.range
Adzz opened this issue · comments
Hello, thanks for the great library.
Would you be open to a PR to add a Decimal.range
function, allowing a start and end Decimal, and a third decimal specifying the step amount?
Decimal.range(Decimal.new("1"), Decimal.new("2"), Decimal.new("0.1"))
Thanks for the suggestion. Since you can do this with the Stream
functions and they give you more flexibility we don't feel this function should be added to the library.
Decimal.new("1")
|> Stream.iterate(&Decimal.add(&1, "0.1"))
|> Stream.take_while(&(Decimal.compare(&1, "2") != :gt))
Stream.unfold(Decimal.new("1"), fn n ->
if Decimal.compare(n, "2") != :gt do
{n, Decimal.add(n, "0.1")}
end
end)