Skip to content

Instantly share code, notes, and snippets.

@joakin
Created January 26, 2023 16:19
Show Gist options
  • Save joakin/8d4ea1b13cfb0322a51ece6ba540ee33 to your computer and use it in GitHub Desktop.
Save joakin/8d4ea1b13cfb0322a51ece6ba540ee33 to your computer and use it in GitHub Desktop.
Debug Json decoders helpers
log : String -> Json.Decode.Decoder a -> Json.Decode.Decoder a
log message =
Json.Decode.map (Debug.log message)
debug : String -> Json.Decode.Decoder a -> Json.Decode.Decoder a
debug message decoder =
Json.Decode.value
|> Json.Decode.andThen (debugHelper message decoder)
debugHelper : String -> Json.Decode.Decoder a -> Json.Decode.Value -> Json.Decode.Decoder a
debugHelper message decoder value =
let
_ =
Debug.log message (Json.Decode.decodeValue decoder value)
in
decoder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment