SortEmptyListInListTest
`List.sort` on a `List (List Int)` that contains `[]` twice 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 45 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 36 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 69 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 35 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/SortEmptyListInListTest] in its title.
Source
The -- CHECK: lines give the expected output.
module SortEmptyListInListTest exposing (main)
{-| `List.sort` on a `List (List Int)` that contains `[]` twice 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.sort [ [ 1 ], emptyL, [ 2 ], emptyL ]
_ = Debug.log "result" result
in
text "done"