@@ -11,6 +11,7 @@ module Web.HttpApiData.Internal where
1111
1212#if __GLASGOW_HASKELL__ < 710
1313import Control.Applicative
14+import Data.Traversable (traverse)
1415#endif
1516import Control.Arrow ((&&&))
1617
@@ -87,6 +88,22 @@ toUrlPieces = fmap toUrlPiece
8788parseUrlPieces :: (Traversable t, FromHttpApiData a) => t Text -> Either Text (t a)
8889parseUrlPieces = traverse parseUrlPiece
8990
91+-- | Convert multiple values to a list of query parameter values.
92+--
93+-- >>> toQueryParams [fromGregorian 2015 10 03, fromGregorian 2015 12 01]
94+-- ["2015-10-03","2015-12-01"]
95+toQueryParams :: (Functor t, ToHttpApiData a) => t a -> t Text
96+toQueryParams = fmap toQueryParam
97+
98+-- | Parse multiple query parameters.
99+--
100+-- >>> parseQueryParams ["1", "2", "3"] :: Either Text [Int]
101+-- Right [1,2,3]
102+-- >>> parseQueryParams ["64", "128", "256"] :: Either Text [Word8]
103+-- Left "out of bounds: `256' (should be between 0 and 255)"
104+parseQueryParams :: (Traversable t, FromHttpApiData a) => t Text -> Either Text (t a)
105+parseQueryParams = traverse parseQueryParam
106+
90107-- | Parse URL path piece in a @'Maybe'@.
91108--
92109-- >>> parseUrlPieceMaybe "12" :: Maybe Int