Elm Exactly
Results / elm-core /

SortByTupleWithMixedConstantsTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`List.sortBy` with a `( Int, List Int )` key whose list is `[]` for positive inputs and `[ -n ]` otherwise orders by the distinct first components.

For `[ -2, -1, 0, 1, 2 ]` the keys are `(-2, [2])`, `(-1, [1])`, `(0, [0])`,
`(1, [])` and `(2, [])`. Every first component is different, so the second
components never decide the order and the input comes back unchanged:
`[-2,-1,0,1,2]`.

Results

elm-0.19.1

passran in 84 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
result: [-2,-1,0,1,2]

elm-0.19.2

passran in 84 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
result: [-2,-1,0,1,2]

elm-0.19.3

passran in 62 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
result: [-2,-1,0,1,2]

lamdera-1.5.0

passran in 69 ms
Output
result: [-2,-1,0,1,2]

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-core/SortByTupleWithMixedConstantsTest] in its title.

Source

The -- CHECK: lines give the expected output.

module SortByTupleWithMixedConstantsTest exposing (main)
{-| `List.sortBy` with a `( Int, List Int )` key whose list is `[]` for positive inputs and `[ -n ]` otherwise orders by the distinct first components.
For `[ -2, -1, 0, 1, 2 ]` the keys are `(-2, [2])`, `(-1, [1])`, `(0, [0])`,
`(1, [])` and `(2, [])`. Every first component is different, so the second
components never decide the order and the input comes back unchanged:
`[-2,-1,0,1,2]`.
-}
-- CHECK: result: [-2,-1,0,1,2]
import Html exposing (text)
keyOf : Int -> ( Int, List Int )
keyOf n =
if n > 0 then
( n, [] )
else
( n, [ -n ] )
main =
let
result : List Int
result = List.sortBy keyOf [ -2, -1, 0, 1, 2 ]
_ = Debug.log "result" result
in
text "done"