@@ -580,9 +580,25 @@ toEncoding2 = liftToEncoding2 toEncoding toEncodingList toEncoding toEncodingLis
580580-- Encoding functions
581581-------------------------------------------------------------------------------
582582
583+-- | Helper function to use with 'liftToEncoding'.
584+-- Useful when writing own 'ToJSON1' instances.
585+--
586+-- @
587+-- newtype F a = F [a]
588+--
589+-- -- This instance encodes String as an array of chars
590+-- instance 'ToJSON1' F where
591+-- 'liftToJSON' tj _ (F xs) = 'liftToJSON' tj ('listValue' tj) xs
592+-- 'liftToEncoding' te _ (F xs) = 'liftToEncoding' te ('listEncoding' te) xs
593+--
594+-- instance 'Data.Aeson.FromJSON.FromJSON1' F where
595+-- 'Data.Aeson.FromJSON.liftParseJSON' p _ v = F \<$\> 'Data.Aeson.FromJSON.liftParseJSON' p ('Data.Aeson.FromJSON.listParser' p) v
596+-- @
583597listEncoding :: (a -> Encoding) -> [a] -> Encoding
584598listEncoding = E.list
599+{-# INLINE listEncoding #-}
585600
601+-- | Helper function to use with 'liftToJSON', see 'listEncoding'.
586602listValue :: (a -> Value) -> [a] -> Value
587603listValue f = Array . V.fromList . map f
588604{-# INLINE listValue #-}