elm-community / list-extra

Convenience functions for working with List.
http://package.elm-lang.org/packages/elm-community/list-extra/latest
MIT License
135 stars 59 forks source link

Remove iterate #70

Closed pzp1997 closed 7 years ago

pzp1997 commented 7 years ago

There are a number of problems with the iterate function that lead me to believe that it should be removed. At the very least, we should change its signature and rename it.

Iterated functions are almost entirely unrelated to lists. This function belongs in (the hypothetical) Function.Extra not List.Extra (a similar objection was raised to #39 which attempted to add a function for repeated composition).

The name is confusing. The first thing that I (and I presume most other people as well) think of when presented with the words iterate and list is accessing the values of a list in order. Yet iterate has nothing to do with this, instead deriving its name from the mathematical notion of an iterated function (also known as repeated function application).

The current API is awkward and heavily lends from Haskell. In Haskell, presumably where the idea for this function came from, the (Elm translated) signature is (a -> a) -> a -> List a. This works great for Haskell because it supports infinite lists. Elm, on the other hand, does not so the current implementation uses a Maybe to indicate when the iteration should stop. Not only is this awkward but it is also inconsistent with the rest of the library. (If we choose to keep it, the function should instead accept an argument for the desired number of applications and a While variant should be created that accepts a predicate for when to stop.)

Limited use. The example in the current documentation is pretty weak (in particular it is better to use List.range 2010 2030 for that kind of thinig). I was struggling to think of a better example to replace it. All of the things I thought of could be done much more cleanly using other functions.