Elm Exactly
Results / elm-core /

StringAstralFoldTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`String.foldl` and `String.foldr` visit a character outside the Basic
Multilingual Plane, such as an emoji, once, as one `Char`.

Counting with a fold gives 1 for `"๐Ÿ˜€"` and 3 for `"a๐Ÿ˜€b"`, from either end.
Consing each `Char.toCode` onto a list gives `[98,128512,97]` with `foldl` and
`[97,128512,98]` with `foldr`, so `foldr` sees the same characters in reverse
order, with the emoji whole (128512 is `0x1F600`).

Results

elm-0.19.1

passran in 43 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
foldl_astral: 1
foldl_mixed: 3
foldr_mixed: 3
foldl_codes: [98,128512,97]
foldr_codes: [97,128512,98]

elm-0.19.2

passran in 42 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
foldl_astral: 1
foldl_mixed: 3
foldr_mixed: 3
foldl_codes: [98,128512,97]
foldr_codes: [97,128512,98]

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.
foldl_astral: 1
foldl_mixed: 3
foldr_mixed: 3
foldl_codes: [98,128512,97]
foldr_codes: [97,128512,98]

lamdera-1.5.0

passran in 60 ms
Output
foldl_astral: 1
foldl_mixed: 3
foldr_mixed: 3
foldl_codes: [98,128512,97]
foldr_codes: [97,128512,98]

Discussions

Discuss this testยทSearch the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module StringAstralFoldTest exposing (main)
{-| `String.foldl` and `String.foldr` visit a character outside the Basic
Multilingual Plane, such as an emoji, once, as one `Char`.
Counting with a fold gives 1 for `"๐Ÿ˜€"` and 3 for `"a๐Ÿ˜€b"`, from either end.
Consing each `Char.toCode` onto a list gives `[98,128512,97]` with `foldl` and
`[97,128512,98]` with `foldr`, so `foldr` sees the same characters in reverse
order, with the emoji whole (128512 is `0x1F600`).
-}
-- CHECK: foldl_astral: 1
-- CHECK: foldl_mixed: 3
-- CHECK: foldr_mixed: 3
-- CHECK: foldl_codes: [98,128512,97]
-- CHECK: foldr_codes: [97,128512,98]
import Html exposing (text)
main =
let
_ =
Debug.log "foldl_astral" (String.foldl (\_ n -> n + 1) 0 "๐Ÿ˜€")
_ =
Debug.log "foldl_mixed" (String.foldl (\_ n -> n + 1) 0 "a๐Ÿ˜€b")
_ =
Debug.log "foldr_mixed" (String.foldr (\_ n -> n + 1) 0 "a๐Ÿ˜€b")
_ =
Debug.log "foldl_codes" (String.foldl (\c acc -> Char.toCode c :: acc) [] "a๐Ÿ˜€b")
_ =
Debug.log "foldr_codes" (String.foldr (\c acc -> Char.toCode c :: acc) [] "a๐Ÿ˜€b")
in
text "done"