SortByAlwaysEmptyListKeyTest
`List.sortBy` with a key function that returns `[]` for every element leaves the list in its original order. `emptyKey` ignores its argument and returns `[]`. All keys are equal, and `List.sortBy` is stable, so `[ 3, 1, 2 ]` stays `[3,1,2]`.
Results
elm-0.19.1
passran in 73 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. result: [3,1,2]
elm-0.19.2
passran in 78 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. result: [3,1,2]
elm-0.19.3
passran in 65 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. result: [3,1,2]
lamdera-1.5.0
passran in 58 msOutput
result: [3,1,2]
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/SortByAlwaysEmptyListKeyTest] in its title.
Source
The -- CHECK: lines give the expected output.
module SortByAlwaysEmptyListKeyTest exposing (main)
{-| `List.sortBy` with a key function that returns `[]` for every element leaves the list in its original order.
`emptyKey` ignores its argument and returns `[]`. All keys are equal, and
`List.sortBy` is stable, so `[ 3, 1, 2 ]` stays `[3,1,2]`.
-}
-- CHECK: result: [3,1,2]
import Html exposing (text)
emptyKey : Int -> List Int
emptyKey _ =
[]
main =
let
result : List Int
result = List.sortBy emptyKey [ 3, 1, 2 ]
_ = Debug.log "result" result
in
text "done"