ListCompoundElementsTest
Lists whose elements are tuples or records support `List.length`, `List.head` and `List.foldl` over a record field.
Results
elm-0.19.1
passran in 50 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. tupleLen: 3 firstTuple: (1,"a") recordLen: 2 firstX: 10 sumX: 30
elm-0.19.2
passran in 85 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. tupleLen: 3 firstTuple: (1,"a") recordLen: 2 firstX: 10 sumX: 30
elm-0.19.3
passran in 78 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. tupleLen: 3 firstTuple: (1,"a") recordLen: 2 firstX: 10 sumX: 30
lamdera-1.5.0
passran in 80 msOutput
tupleLen: 3 firstTuple: (1,"a") recordLen: 2 firstX: 10 sumX: 30
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/ListCompoundElementsTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ListCompoundElementsTest exposing (main)
{-| Lists whose elements are tuples or records support `List.length`, `List.head`
and `List.foldl` over a record field.
-}
-- CHECK: tupleLen: 3
-- CHECK: firstTuple: (1,"a")
-- CHECK: recordLen: 2
-- CHECK: firstX: 10
-- CHECK: sumX: 30
import Html exposing (text)
main =
let
tuples = [ ( 1, "a" ), ( 2, "b" ), ( 3, "c" ) ]
_ = Debug.log "tupleLen" (List.length tuples)
_ = Debug.log "firstTuple" (case List.head tuples of
Just t -> t
Nothing -> ( 0, "" ))
records = [ { x = 10, y = "hello" }, { x = 20, y = "world" } ]
_ = Debug.log "recordLen" (List.length records)
firstX =
case List.head records of
Just r ->
r.x
Nothing ->
0
_ = Debug.log "firstX" firstX
_ = Debug.log "sumX" (List.foldl (\r acc -> acc + r.x) 0 records)
in
text "done"