Elm Exactly
Results / elm-bytes /

DecodeAndThenTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Bytes.Decode.andThen` lets a value already decoded choose the next decoder: a length byte followed by that many bytes of string decodes to `"Hi"`.

Results

elm-0.19.1

passran in 54 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
DecodeAndThenTest: "Hi"

elm-0.19.2

passran in 60 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
DecodeAndThenTest: "Hi"

elm-0.19.3

passran in 68 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
DecodeAndThenTest: "Hi"

lamdera-1.5.0

passran in 53 ms
Output
DecodeAndThenTest: "Hi"

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module DecodeAndThenTest exposing (main)
{-| `Bytes.Decode.andThen` lets a value already decoded choose the next decoder: a length byte followed by that many bytes of string decodes to `"Hi"`.
-}
-- CHECK: DecodeAndThenTest: "Hi"
import Bytes exposing (Bytes)
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
-- Encode: length (1 byte) followed by string
bytes =
E.encode
(E.sequence
[ E.unsignedInt8 2
, E.string "Hi"
]
)
-- Decode length, then decode that many chars
decoder =
D.unsignedInt8
|> D.andThen (\len -> D.string len)
result =
D.decode decoder bytes
|> Maybe.withDefault "FAIL"
_ =
Debug.log "DecodeAndThenTest" result
in
text result