Elm Exactly
Results / elm-bytes /

DecodeMap5Test

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Bytes.Decode.map5 combines five decoders that read consecutive bytes.

Five unsigned 8-bit values 1 to 5 are encoded, and `map5` reads them in order and
sums them, so the logged result is 15. A failed decode would log -1.

Results

elm-0.19.1

passran in 60 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
DecodeMap5Test: 15

elm-0.19.2

passran in 81 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
DecodeMap5Test: 15

elm-0.19.3

passran in 74 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
DecodeMap5Test: 15

lamdera-1.5.0

passran in 36 ms
Output
DecodeMap5Test: 15

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module DecodeMap5Test exposing (main)
{-| Bytes.Decode.map5 combines five decoders that read consecutive bytes.
Five unsigned 8-bit values 1 to 5 are encoded, and `map5` reads them in order and
sums them, so the logged result is 15. A failed decode would log -1.
-}
-- CHECK: DecodeMap5Test: 15
import Bytes exposing (Bytes)
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
bytes =
E.encode
(E.sequence
[ E.unsignedInt8 1
, E.unsignedInt8 2
, E.unsignedInt8 3
, E.unsignedInt8 4
, E.unsignedInt8 5
]
)
decoder =
D.map5 (\a b c d e -> a + b + c + d + e)
D.unsignedInt8
D.unsignedInt8
D.unsignedInt8
D.unsignedInt8
D.unsignedInt8
result =
D.decode decoder bytes
|> Maybe.withDefault -1
_ =
Debug.log "DecodeMap5Test" result
in
text (String.fromInt result)