Skip to content

Instantly share code, notes, and snippets.

@jinjor
Created May 20, 2018 09:00
Show Gist options
  • Save jinjor/615e6ca072dca60e5b65926bd4684dcf to your computer and use it in GitHub Desktop.
Save jinjor/615e6ca072dca60e5b65926bd4684dcf to your computer and use it in GitHub Desktop.
json = """{ "name": "tom", "age": 42 }"""
decodeString (maybe (field "age" int )) json -- Ok (Just 42)
decodeString (maybe (field "name" int )) json -- Ok Nothing
decodeString (maybe (field "height" float)) json -- Ok Nothing
decodeString (maybe (field "height" float)) "null" -- Ok Nothing
decodeString (maybe (field "height" float)) "\"hello\"" -- Ok Nothing
decodeString (maybe (field "height" float)) "" -- Err ...
decodeString (field "age" (maybe int )) json -- Ok (Just 42)
decodeString (field "name" (maybe int )) json -- Ok Nothing
decodeString (field "height" (maybe float)) json -- Err ...
decodeString (field "height" (maybe float)) "null" -- Err ...
decodeString (field "height" (maybe float)) "\"hello\"" -- Err ...
decodeString (field "height" (maybe float)) "" -- Err ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment