DecodeMapTest
Bytes.Decode.map applies a function to the value a decoder produces. A single unsigned byte 42 is decoded through `map (\x -> x * 2)`, so the logged result is 84. A failed decode would log -1.
Results
elm-0.19.1
passran in 50 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. DecodeMapTest: 84
elm-0.19.2
passran in 66 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. DecodeMapTest: 84
elm-0.19.3
passran in 70 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. DecodeMapTest: 84
lamdera-1.5.0
passran in 61 msOutput
DecodeMapTest: 84
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/DecodeMapTest] in its title.
Source
The -- CHECK: lines give the expected output.
module DecodeMapTest exposing (main)
{-| Bytes.Decode.map applies a function to the value a decoder produces.
A single unsigned byte 42 is decoded through `map (\x -> x * 2)`, so the logged
result is 84. A failed decode would log -1.
-}
-- CHECK: DecodeMapTest: 84
import Bytes exposing (Bytes)
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
bytes =
E.encode (E.unsignedInt8 42)
decoder =
D.map (\x -> x * 2) D.unsignedInt8
result =
D.decode decoder bytes
|> Maybe.withDefault -1
_ =
Debug.log "DecodeMapTest" result
in
text (String.fromInt result)