DecodeMap2Test
`Bytes.Decode.map2` combines two decoders in order: two bytes, 100 and 200, decoded and added with `(+)` give the `Int` 300.
Results
elm-0.19.1
passran in 67 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. DecodeMap2Test: 300
elm-0.19.2
passran in 50 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. DecodeMap2Test: 300
elm-0.19.3
passran in 65 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. DecodeMap2Test: 300
lamdera-1.5.0
passran in 54 msOutput
DecodeMap2Test: 300
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/DecodeMap2Test] in its title.
Source
The -- CHECK: lines give the expected output.
module DecodeMap2Test exposing (main)
{-| `Bytes.Decode.map2` combines two decoders in order: two bytes, 100 and 200, decoded and added with `(+)` give the `Int` 300.
-}
-- CHECK: DecodeMap2Test: 300
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
bytes =
E.encode
(E.sequence
[ E.unsignedInt8 100
, E.unsignedInt8 200
]
)
decoder =
D.map2 (+) D.unsignedInt8 D.unsignedInt8
result =
D.decode decoder bytes
|> Maybe.withDefault -1
_ =
Debug.log "DecodeMap2Test" result
in
text (String.fromInt result)