Add a Contravariant instance for Array encoder

This commit is contained in:
Nikita Volkov 2019-05-26 18:05:48 +03:00
parent d7d80ede8e
commit 3fcbcb23ba
2 changed files with 5 additions and 0 deletions

View File

@ -339,6 +339,7 @@ Please note that the PostgreSQL @IN@ keyword does not accept an array, but rathe
values, thus this encoder is not suited for that. Use a @value = ANY($1)@ condition instead.
-}
newtype Array a = Array (Array.Array a)
deriving (Contravariant)
{-|
Lifts a 'Value' encoder into an 'Array' encoder.

View File

@ -9,6 +9,10 @@ import qualified Text.Builder as C
data Array a =
Array B.OID B.OID (Bool -> a -> A.Array) (a -> C.Builder)
instance Contravariant Array where
contramap fn (Array valueOid arrayOid encoder renderer) =
Array valueOid arrayOid (\ intDateTimes -> encoder intDateTimes . fn) (renderer . fn)
{-# INLINE value #-}
value :: B.OID -> B.OID -> (Bool -> a -> A.Encoding) -> (a -> C.Builder) -> Array a
value valueOID arrayOID encoder =