SortByIdentityEmptyListTest
`List.sortBy identity` on a list of `List Int` values, two of which are `[]`, puts the empty lists first. Lists compare element by element, and `[]` is less than any non-empty list, so `[ [ 1 ], [], [ 2 ], [] ]` sorts to `[[],[],[1],[2]]`.
Results
elm-0.19.1
passran in 47 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. result: [[],[],[1],[2]]
elm-0.19.2
passran in 43 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. result: [[],[],[1],[2]]
elm-0.19.3
passran in 63 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. result: [[],[],[1],[2]]
lamdera-1.5.0
passran in 48 msOutput
result: [[],[],[1],[2]]
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/SortByIdentityEmptyListTest] in its title.
Source
The -- CHECK: lines give the expected output.
module SortByIdentityEmptyListTest exposing (main)
{-| `List.sortBy identity` on a list of `List Int` values, two of which are `[]`, puts the empty lists first.
Lists compare element by element, and `[]` is less than any non-empty list, so
`[ [ 1 ], [], [ 2 ], [] ]` sorts to `[[],[],[1],[2]]`.
-}
-- CHECK: result: [[],[],[1],[2]]
import Html exposing (text)
main =
let
emptyL : List Int
emptyL = []
result : List (List Int)
result = List.sortBy identity [ [ 1 ], emptyL, [ 2 ], emptyL ]
_ = Debug.log "result" result
in
text "done"