diff --git a/CHANGELOG.md b/CHANGELOG.md index 05d0c39..7170a3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +0.6.3 + +* Add To/FromForm instances for () and Void + 0.6.2 * Support GHC-9.12 diff --git a/http-api-data.cabal b/http-api-data.cabal index 3a72763..c9d72ae 100644 --- a/http-api-data.cabal +++ b/http-api-data.cabal @@ -1,6 +1,6 @@ cabal-version: 1.12 name: http-api-data -version: 0.6.2.1 +version: 0.6.3 synopsis: Converting to/from HTTP API data like URL pieces, headers and query parameters. category: Web diff --git a/src/Web/Internal/FormUrlEncoded.hs b/src/Web/Internal/FormUrlEncoded.hs index 08d125a..3ab9b02 100644 --- a/src/Web/Internal/FormUrlEncoded.hs +++ b/src/Web/Internal/FormUrlEncoded.hs @@ -49,7 +49,7 @@ import Data.Time.Compat (Day, LocalTime, NominalDiffTime, UTCTime, ZonedTime) import Data.Time.Calendar.Month.Compat (Month) import Data.Time.Calendar.Quarter.Compat (Quarter, QuarterOfYear (..)) -import Data.Void (Void) +import Data.Void (Void, absurd) import Data.Word (Word16, Word32, Word64, Word8) import GHC.Exts (Constraint, IsList (..)) import GHC.Generics @@ -267,6 +267,16 @@ class ToForm a where instance ToForm Form where toForm = id +-- | +-- +-- @since 0.6.3 +instance ToForm Void where toForm = absurd + +-- | +-- +-- @since 0.6.3 +instance ToForm () where toForm _ = Form HashMap.empty + instance (ToFormKey k, ToHttpApiData v) => ToForm [(k, v)] where toForm = fromList . map (toFormKey *** toQueryParam) @@ -413,6 +423,16 @@ class FromForm a where instance FromForm Form where fromForm = pure +-- | +-- +-- @since 0.6.3 +instance FromForm Void where fromForm _ = Left "fromForm: Void" + +-- | +-- +-- @since 0.6.3 +instance FromForm () where fromForm _ = Right () + -- | _NOTE:_ this conversion is unstable and may result in different key order (but not values). instance (FromFormKey k, FromHttpApiData v) => FromForm [(k, v)] where fromForm = fmap (concatMap (\(k, vs) -> map ((,) k) vs)) . toEntriesByKey diff --git a/stack.yaml b/stack.yaml index aa9b6e2..ae7f1fa 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-12.10 +resolver: lts-23.3 packages: - '.' flags: