brandonchinn178 / toml-reader

Haskell library for parsing v1.0 TOML files
https://hackage.haskell.org/package/toml-reader
BSD 3-Clause "New" or "Revised" License
13 stars 6 forks source link

Add more Decoder helpers #11

Open brandonchinn178 opened 1 year ago

brandonchinn178 commented 1 year ago
toDecoder :: DecodeM a -> Decoder a
toDecoder m = makeDecoder (const m)

applyDecoder :: Decoder a -> Value -> Decoder a
applyDecoder decoder = toDecoder . runDecoder decoder

-- Type mismatch: Expected String, got: <value>
typeMismatch :: Text -> Decoder a
typeMismatch' :: Text -> Value -> DecodeM a

-- Invalid value: <msg>, got: <value>
invalidValue :: Text -> Decoder a
invalidValue' :: Text -> Value -> DecodeM a

hide DecodeM functions; recommend invalidValue or typeMismatch over fail