elm-community / json-extra

Convenience functions for working with Json.
http://package.elm-lang.org/packages/elm-community/json-extra/latest
MIT License
37 stars 16 forks source link

Add optionalField #7

Closed rtfeldman closed 7 years ago

rtfeldman commented 7 years ago

This is a standalone alternative to optional from elm-decode-pipeline.

It's a field-specific variation on maybe, where the only difference is that if the field is present but malformed, decoding fails. (Whereas with maybe (field "foo" string), a field that is present but malformed succeeds with Nothing, meaning you don't find out that you received some malformed json.)

mgold commented 7 years ago

LGTM. Arguably this should be how core/maybe works, but that's down the road.

rtfeldman commented 7 years ago

Well maybe is more general - it's not specific to decoding objects, and so doesn't take a fieldName string.

(Having said that, perhaps if this exists there's no longer a reasonable use case for maybe...)