Elm Exactly
Results / elm-core /

JsArrayIndexedFilterTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Array.indexedMap`, `Array.filter` and `Array.toIndexedList` give the expected results on small `Array Int` values.

`indexedMap` pairing index with value and `toIndexedList` both give `[(0,10),(1,20),(2,30)]` for `[10, 20, 30]`, and filtering `[1, 2, 3, 4, 5, 6]` for even numbers keeps `[2, 4, 6]`.

Results

elm-0.19.1

passran in 64 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
indexedMap1: [(0,10),(1,20),(2,30)]
filter1: [2,4,6]
toIndexedList1: [(0,10),(1,20),(2,30)]

elm-0.19.2

passran in 78 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
indexedMap1: [(0,10),(1,20),(2,30)]
filter1: [2,4,6]
toIndexedList1: [(0,10),(1,20),(2,30)]

elm-0.19.3

passran in 50 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
indexedMap1: [(0,10),(1,20),(2,30)]
filter1: [2,4,6]
toIndexedList1: [(0,10),(1,20),(2,30)]

lamdera-1.5.0

passran in 85 ms
Output
indexedMap1: [(0,10),(1,20),(2,30)]
filter1: [2,4,6]
toIndexedList1: [(0,10),(1,20),(2,30)]

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module JsArrayIndexedFilterTest exposing (main)
{-| `Array.indexedMap`, `Array.filter` and `Array.toIndexedList` give the expected results on small `Array Int` values.
`indexedMap` pairing index with value and `toIndexedList` both give `[(0,10),(1,20),(2,30)]` for `[10, 20, 30]`, and filtering `[1, 2, 3, 4, 5, 6]` for even numbers keeps `[2, 4, 6]`.
-}
-- CHECK: indexedMap1: [(0,10),(1,20),(2,30)]
-- CHECK: filter1: [2,4,6]
-- CHECK: toIndexedList1: [(0,10),(1,20),(2,30)]
import Array
import Html exposing (text)
main =
let
arr = Array.fromList [10, 20, 30]
_ = Debug.log "indexedMap1" (Array.toList (Array.indexedMap (\i v -> (i, v)) arr))
_ = Debug.log "filter1" (Array.toList (Array.filter (\x -> modBy 2 x == 0) (Array.fromList [1, 2, 3, 4, 5, 6])))
_ = Debug.log "toIndexedList1" (Array.toIndexedList arr)
in
text "done"