Last active
May 9, 2017 08:54
-
-
Save rohanorton/d21a9a55d94223837c0de329f2bfb000 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
optional "note" string "" | |
optional "note" (map Just string) Nothing | |
optional "note" (map (\x -> if x == "" then Nothing else Just x) string) Nothing | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Json.Encode as Json | |
type alias NotePayload = { notes : Maybe String } | |
-- { "notes": "abc" } | |
encodeNotePayload : NotePayload -> Value | |
encodeNotePayload payload = | |
Json.object [ ("notes", encodeMaybeString payload.notes ) ] | |
encodeMaybeString : Maybe String -> Value | |
encodeMaybeString maybeString = | |
case maybeString of | |
Nothing -> Json.null | |
Just str -> Json.string str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment