purescript-contrib / purescript-argonaut-codecs

JSON serialization and deserialization with Argonaut.
MIT License
48 stars 46 forks source link

add decoder for NonEmptyString #91

Closed srghma closed 3 years ago

srghma commented 3 years ago

can add after 0.14, because cannot run tests now

instance decodeJsonCodePoint :: DecodeJson NonEmptyString where
  decodeJson = decodeNonEmptyString

decodeNonEmptyString :: Json -> Either JsonDecodeError NonEmptyString
decodeNonEmptyString json =
  note (Named "NonEmptyString" $ UnexpectedValue json)
    =<< map (NonEmptyString.fromString) (decodeString json)
srghma commented 3 years ago

we could also add

decodeNonempty :: Json -> Either JsonDecodeError String
decodeNonempty = map NonEmptyString.toString <<< decodeNonEmptyString

like haskell lib envparse does

they have str :: String and nonempty :: String

thomashoneyman commented 3 years ago

I think this is sensible to add, and I'd accept a PR for it. If you don't want to build using a 0.14 release candidate you could always check out the last commit before the 0.14 changes, make your update, and then rebase onto master (I think, at least).