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

Add reverseMap #48

Closed pzp1997 closed 7 years ago

pzp1997 commented 7 years ago

reverseMap is a pretty handy function for efficiently mapping and reversing a List. It is inspired by OCaml's List.rev_map function.

An example use case is if you have a list of events in chronological order, and you would like to display them in reverse chronological order (like on a résumé or a todo list). Using reverseMap, you can convert each event into an Html msg and reverse the order of the events all in a single pass.

Chadtech commented 7 years ago

I really cant see a reason not to merge this. Its just a more performant, and more readable combination of List.map f >> List.reverse.

I'll leave this PR open a bit longer, and if nothing changes I'll merge.