generate function
gbagan opened this issue · 2 comments
gbagan commented
I think this function can be useful
generate :: Int -> (Int -> a) -> Array a
It builds an array of the given length by applying the function to each index.
I use it in many projects.
I can create a PR if necessary.
garyb commented
I think I just map over a range when I've needed something like this in the past - that's slightly less efficient than it could be, but it's pretty much just the cost of one array allocation.
gbagan commented
I understand your point of view.
In addition to the overhead of map over range, I see the following advantages in favor of a generate function.
generateis present in theData.Vectormodule of Haskell.0 .. (n-1) <#> f(instead ofgenerate n f) requires handling the case where n <= 0 (in particular when n = 0)