Elm Exactly
Results / elm-core /

SortCharTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`List.sort`, `List.sortWith` and `List.sortBy` order a `List Char` correctly and return the elements as `Char` values.

The test checks four results:

  - `List.sort` puts `['c', 'a', 'b']` in order.
  - `List.sortWith compare` puts `['z', 'x', 'y']` in order.
  - `List.sortWith` with the comparison flipped sorts `['a', 'b', 'c']` into
    reverse order.
  - `List.sortBy Char.toCode` orders by character code, so the uppercase
    letters come before the lowercase ones: `['A','Z','a','z']`.

Results

elm-0.19.1

passran in 62 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
sort: ['a','b','c']
sortWith: ['x','y','z']
reverse: ['c','b','a']
sortByCode: ['A','Z','a','z']

elm-0.19.2

passran in 80 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
sort: ['a','b','c']
sortWith: ['x','y','z']
reverse: ['c','b','a']
sortByCode: ['A','Z','a','z']

elm-0.19.3

passran in 59 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
sort: ['a','b','c']
sortWith: ['x','y','z']
reverse: ['c','b','a']
sortByCode: ['A','Z','a','z']

lamdera-1.5.0

passran in 76 ms
Output
sort: ['a','b','c']
sortWith: ['x','y','z']
reverse: ['c','b','a']
sortByCode: ['A','Z','a','z']

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module SortCharTest exposing (main)
{-| `List.sort`, `List.sortWith` and `List.sortBy` order a `List Char` correctly and return the elements as `Char` values.
The test checks four results:
- `List.sort` puts `['c', 'a', 'b']` in order.
- `List.sortWith compare` puts `['z', 'x', 'y']` in order.
- `List.sortWith` with the comparison flipped sorts `['a', 'b', 'c']` into
reverse order.
- `List.sortBy Char.toCode` orders by character code, so the uppercase
letters come before the lowercase ones: `['A','Z','a','z']`.
-}
-- CHECK: sort: ['a','b','c']
-- CHECK: sortWith: ['x','y','z']
-- CHECK: reverse: ['c','b','a']
-- CHECK: sortByCode: ['A','Z','a','z']
import Char
import Html exposing (text)
main =
let
_ = Debug.log "sort" (List.sort ['c', 'a', 'b'])
_ = Debug.log "sortWith" (List.sortWith compare ['z', 'x', 'y'])
_ = Debug.log "reverse" (List.sortWith (\a b -> compare b a) ['a', 'b', 'c'])
_ = Debug.log "sortByCode" (List.sortBy Char.toCode ['a', 'Z', 'z', 'A'])
in
text "done"