jfmengels / elm-review-simplify

Provides elm-review rules to simplify your Elm code
https://package.elm-lang.org/packages/jfmengels/elm-review-simplify/latest/
BSD 3-Clause "New" or "Revised" License
20 stars 9 forks source link

Redundant sorting #155

Closed jfmengels closed 11 months ago

jfmengels commented 12 months ago

List.sort >> List.sort is redundant and can be simplified to List.sort.


For List.sortWith f >> List.sortWith g, logically we could remove List.sortWith f, as whatever ordering f does gets overriden by g, but that's not always true, so we should not do this (unless we check and notice that f == g).

Counter-example where the double sorting has an effect (using sortBy which is similar):

data = [ ( 2, 2), ( 1, 100 ), ( 1, 1 ) ]

data |> List.sortBy Tuple.second |> List.sortBy Tuple.first
--> [(1,1),(1,100),(2,2)]

data |> List.sortBy Tuple.first
--> [(1,100),(1,1),(2,2)]