I would like to encode a Maybe String
to string
if it has a concrete value, or null
if it's Nothing
.
At the moment, I use a helper function encodeOptionalString myStr
to get the desired effect. I was wondering if there's a more Elm-like way of doing this. I really like the API of elm-json-decode-pipeline that allows me to write Decode.nullable Decode.string
for decoding.
encodeOptionalString : Maybe String -> Encode.Value
encodeOptionalString s =
case s of
Just s_ ->
Encode.string s_
Nothing ->
Encode.null