module Hasql.Private.Decoders.Array where

import Hasql.Private.Prelude
import qualified PostgreSQL.Binary.Decoding as A


newtype Array a =
  Array (ReaderT Bool A.Array a)
  deriving (a -> Array b -> Array a
(a -> b) -> Array a -> Array b
(forall a b. (a -> b) -> Array a -> Array b)
-> (forall a b. a -> Array b -> Array a) -> Functor Array
forall a b. a -> Array b -> Array a
forall a b. (a -> b) -> Array a -> Array b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Array b -> Array a
$c<$ :: forall a b. a -> Array b -> Array a
fmap :: (a -> b) -> Array a -> Array b
$cfmap :: forall a b. (a -> b) -> Array a -> Array b
Functor)

{-# INLINE run #-}
run :: Array a -> Bool -> A.Value a
run :: Array a -> Bool -> Value a
run (Array ReaderT Bool Array a
imp) Bool
env =
  Array a -> Value a
forall a. Array a -> Value a
A.array (ReaderT Bool Array a -> Bool -> Array a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT Bool Array a
imp Bool
env)

{-# INLINE dimension #-}
dimension :: (forall m. Monad m => Int -> m a -> m b) -> Array a -> Array b
dimension :: (forall (m :: * -> *). Monad m => Int -> m a -> m b)
-> Array a -> Array b
dimension forall (m :: * -> *). Monad m => Int -> m a -> m b
replicateM (Array ReaderT Bool Array a
imp) =
  ReaderT Bool Array b -> Array b
forall a. ReaderT Bool Array a -> Array a
Array (ReaderT Bool Array b -> Array b)
-> ReaderT Bool Array b -> Array b
forall a b. (a -> b) -> a -> b
$ (Bool -> Array b) -> ReaderT Bool Array b
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((Bool -> Array b) -> ReaderT Bool Array b)
-> (Bool -> Array b) -> ReaderT Bool Array b
forall a b. (a -> b) -> a -> b
$ \Bool
env -> (forall (m :: * -> *). Monad m => Int -> m a -> m b)
-> Array a -> Array b
forall a b.
(forall (m :: * -> *). Monad m => Int -> m a -> m b)
-> Array a -> Array b
A.dimensionArray forall (m :: * -> *). Monad m => Int -> m a -> m b
replicateM (ReaderT Bool Array a -> Bool -> Array a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT Bool Array a
imp Bool
env)

{-# INLINE value #-}
value :: (Bool -> A.Value a) -> Array (Maybe a)
value :: (Bool -> Value a) -> Array (Maybe a)
value Bool -> Value a
decoder' =
  ReaderT Bool Array (Maybe a) -> Array (Maybe a)
forall a. ReaderT Bool Array a -> Array a
Array (ReaderT Bool Array (Maybe a) -> Array (Maybe a))
-> ReaderT Bool Array (Maybe a) -> Array (Maybe a)
forall a b. (a -> b) -> a -> b
$ (Bool -> Array (Maybe a)) -> ReaderT Bool Array (Maybe a)
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((Bool -> Array (Maybe a)) -> ReaderT Bool Array (Maybe a))
-> (Bool -> Array (Maybe a)) -> ReaderT Bool Array (Maybe a)
forall a b. (a -> b) -> a -> b
$ Value a -> Array (Maybe a)
forall a. Value a -> Array (Maybe a)
A.nullableValueArray (Value a -> Array (Maybe a))
-> (Bool -> Value a) -> Bool -> Array (Maybe a)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Value a
decoder'

{-# INLINE nonNullValue #-}
nonNullValue :: (Bool -> A.Value a) -> Array a
nonNullValue :: (Bool -> Value a) -> Array a
nonNullValue Bool -> Value a
decoder' =
  ReaderT Bool Array a -> Array a
forall a. ReaderT Bool Array a -> Array a
Array (ReaderT Bool Array a -> Array a)
-> ReaderT Bool Array a -> Array a
forall a b. (a -> b) -> a -> b
$ (Bool -> Array a) -> ReaderT Bool Array a
forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT ((Bool -> Array a) -> ReaderT Bool Array a)
-> (Bool -> Array a) -> ReaderT Bool Array a
forall a b. (a -> b) -> a -> b
$ Value a -> Array a
forall a. Value a -> Array a
A.valueArray (Value a -> Array a) -> (Bool -> Value a) -> Bool -> Array a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> Value a
decoder'