Elm Exactly
Results / elm-core /

JsArrayMapFoldTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Array.map`, `Array.foldl` and `Array.foldr` visit an array's elements in the right order.

`Array.map` doubles each of `[1,2,3]`. `Array.foldl (+) 0` sums 1 to 5 to 15. `Array.foldr (::) []` over 1 to 5 rebuilds the list in its original order, which shows that `foldr` starts from the last element.

Results

elm-0.19.1

passran in 80 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
map1: [2,4,6]
foldl_sum: 15
foldr_build: [1,2,3,4,5]

elm-0.19.2

passran in 70 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
map1: [2,4,6]
foldl_sum: 15
foldr_build: [1,2,3,4,5]

elm-0.19.3

passran in 49 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
map1: [2,4,6]
foldl_sum: 15
foldr_build: [1,2,3,4,5]

lamdera-1.5.0

passran in 70 ms
Output
map1: [2,4,6]
foldl_sum: 15
foldr_build: [1,2,3,4,5]

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module JsArrayMapFoldTest exposing (main)
{-| `Array.map`, `Array.foldl` and `Array.foldr` visit an array's elements in the right order.
`Array.map` doubles each of `[1,2,3]`. `Array.foldl (+) 0` sums 1 to 5 to 15. `Array.foldr (::) []` over 1 to 5 rebuilds the list in its original order, which shows that `foldr` starts from the last element.
-}
-- CHECK: map1: [2,4,6]
-- CHECK: foldl_sum: 15
-- CHECK: foldr_build: [1,2,3,4,5]
import Array
import Html exposing (text)
main =
let
arr = Array.fromList [1, 2, 3]
_ = Debug.log "map1" (Array.toList (Array.map (\x -> x * 2) arr))
_ = Debug.log "foldl_sum" (Array.foldl (+) 0 (Array.fromList [1, 2, 3, 4, 5]))
_ = Debug.log "foldr_build" (Array.foldr (::) [] (Array.fromList [1, 2, 3, 4, 5]))
in
text "done"