{-# language DataKinds #-}
{-# language DisambiguateRecordFields #-}
{-# language NamedFieldPuns #-}
{-# language TypeFamilies #-}
module Rel8.Schema.Context.Result
( fromHEitherTable, toHEitherTable
, fromHListTable, toHListTable
, fromHMaybeTable, toHMaybeTable
, fromHNonEmptyTable, toHNonEmptyTable
, fromHTheseTable, toHTheseTable
)
where
import Data.Functor ( ($>) )
import Data.List.NonEmpty ( NonEmpty )
import Prelude hiding ( null )
import Rel8.Schema.Context ( Result( Result ) )
import Rel8.Schema.HTable ( HTable )
import Rel8.Schema.HTable.Context ( H )
import Rel8.Schema.HTable.Either ( HEitherTable(..) )
import Rel8.Schema.HTable.Identity ( HIdentity(..) )
import Rel8.Schema.HTable.Maybe ( HMaybeTable(..) )
import Rel8.Schema.HTable.List ( HListTable )
import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
import Rel8.Schema.HTable.Nullify ( hnulls, hnullify, hunnullify )
import Rel8.Schema.HTable.These ( HTheseTable(..) )
import Rel8.Schema.HTable.Vectorize ( hvectorize, hunvectorize )
import Rel8.Schema.Nullability
( Nullability( Nullable, NonNullable )
)
import Rel8.Schema.Spec ( Spec( Spec ), SSpec(..) )
import Rel8.Type.Tag ( EitherTag( IsLeft, IsRight ), MaybeTag( IsJust ) )
import Data.These ( These( This, That, These ) )
import Data.These.Combinators ( justHere, justThere )
toHEitherTable :: (HTable t, HTable u)
=> Either (t (H Result)) (u (H Result))
-> HEitherTable t u (H Result)
toHEitherTable :: Either (t (H Result)) (u (H Result)) -> HEitherTable t u (H Result)
toHEitherTable = (t (H Result) -> HEitherTable t u (H Result))
-> (u (H Result) -> HEitherTable t u (H Result))
-> Either (t (H Result)) (u (H Result))
-> HEitherTable t u (H Result)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either t (H Result) -> HEitherTable t u (H Result)
forall (left :: HKTable) (right :: HKTable).
(HTable left, HTable right) =>
left (H Result) -> HEitherTable left right (H Result)
hleft u (H Result) -> HEitherTable t u (H Result)
forall (left :: HKTable) (right :: HKTable).
(HTable left, HTable right) =>
right (H Result) -> HEitherTable left right (H Result)
hright
where
hleft :: left (H Result) -> HEitherTable left right (H Result)
hleft left (H Result)
table = HEitherTable :: forall (left :: HKTable) (right :: HKTable) (context :: HContext).
HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) context
-> HNullify left context
-> HNullify right context
-> HEitherTable left right context
HEitherTable
{ htag :: HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) (H Result)
htag = Result ('Spec '["isRight"] 'Required EitherTag EitherTag)
-> HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) (H Result)
forall (context :: Spec -> *) (spec :: Spec).
context spec -> HIdentity spec (H context)
HIdentity (EitherTag
-> Result ('Spec '["isRight"] 'Required EitherTag EitherTag)
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result EitherTag
IsLeft)
, hleft :: HNullify left (H Result)
hleft = (forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType)))
-> left (H Result) -> HNullify left (H Result)
forall (t :: HKTable) (context :: Spec -> *).
HTable t =>
(forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType (Maybe dbType)))
-> t (H context) -> HNullify t (H context)
hnullify forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
nullifier left (H Result)
table
, hright :: HNullify right (H Result)
hright = (forall (labels :: Labels) (necessity :: Necessity) dbType.
Result ('Spec labels necessity dbType (Maybe dbType)))
-> HNullify right (H Result)
forall (t :: HKTable) (context :: Spec -> *).
HTable t =>
(forall (labels :: Labels) (necessity :: Necessity) dbType.
context ('Spec labels necessity dbType (Maybe dbType)))
-> HNullify t (H context)
hnulls forall (labels :: Labels) (necessity :: Necessity) dbType.
Result ('Spec labels necessity dbType (Maybe dbType))
null
}
hright :: right (H Result) -> HEitherTable left right (H Result)
hright right (H Result)
table = HEitherTable :: forall (left :: HKTable) (right :: HKTable) (context :: HContext).
HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) context
-> HNullify left context
-> HNullify right context
-> HEitherTable left right context
HEitherTable
{ htag :: HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) (H Result)
htag = Result ('Spec '["isRight"] 'Required EitherTag EitherTag)
-> HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) (H Result)
forall (context :: Spec -> *) (spec :: Spec).
context spec -> HIdentity spec (H context)
HIdentity (EitherTag
-> Result ('Spec '["isRight"] 'Required EitherTag EitherTag)
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result EitherTag
IsRight)
, hleft :: HNullify left (H Result)
hleft = (forall (labels :: Labels) (necessity :: Necessity) dbType.
Result ('Spec labels necessity dbType (Maybe dbType)))
-> HNullify left (H Result)
forall (t :: HKTable) (context :: Spec -> *).
HTable t =>
(forall (labels :: Labels) (necessity :: Necessity) dbType.
context ('Spec labels necessity dbType (Maybe dbType)))
-> HNullify t (H context)
hnulls forall (labels :: Labels) (necessity :: Necessity) dbType.
Result ('Spec labels necessity dbType (Maybe dbType))
null
, hright :: HNullify right (H Result)
hright = (forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType)))
-> right (H Result) -> HNullify right (H Result)
forall (t :: HKTable) (context :: Spec -> *).
HTable t =>
(forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType (Maybe dbType)))
-> t (H context) -> HNullify t (H context)
hnullify forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
nullifier right (H Result)
table
}
{-# INLINABLE toHEitherTable #-}
fromHEitherTable :: (HTable t, HTable u)
=> HEitherTable t u (H Result)
-> Either (t (H Result)) (u (H Result))
fromHEitherTable :: HEitherTable t u (H Result) -> Either (t (H Result)) (u (H Result))
fromHEitherTable HEitherTable {HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) (H Result)
htag :: HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) (H Result)
htag :: forall (left :: HKTable) (right :: HKTable) (context :: HContext).
HEitherTable left right context
-> HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) context
htag, HNullify t (H Result)
hleft :: HNullify t (H Result)
hleft :: forall (left :: HKTable) (right :: HKTable) (context :: HContext).
HEitherTable left right context -> HNullify left context
hleft, HNullify u (H Result)
hright :: HNullify u (H Result)
hright :: forall (left :: HKTable) (right :: HKTable) (context :: HContext).
HEitherTable left right context -> HNullify right context
hright} = case HIdentity
('Spec '["isRight"] 'Required EitherTag EitherTag) (H Result)
htag of
HIdentity (Result tag) -> case a
tag of
a
IsLeft -> Either (t (H Result)) (u (H Result))
-> (t (H Result) -> Either (t (H Result)) (u (H Result)))
-> Maybe (t (H Result))
-> Either (t (H Result)) (u (H Result))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either (t (H Result)) (u (H Result))
forall a. a
err t (H Result) -> Either (t (H Result)) (u (H Result))
forall a b. a -> Either a b
Left (Maybe (t (H Result)) -> Either (t (H Result)) (u (H Result)))
-> Maybe (t (H Result)) -> Either (t (H Result)) (u (H Result))
forall a b. (a -> b) -> a -> b
$ (forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
-> Maybe (Result ('Spec labels necessity dbType a)))
-> HNullify t (H Result) -> Maybe (t (H Result))
forall (t :: HKTable) (m :: * -> *) (context :: Spec -> *).
(HTable t, Apply m) =>
(forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType (Maybe dbType))
-> m (context ('Spec labels necessity dbType a)))
-> HNullify t (H context) -> m (t (H context))
hunnullify forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
-> Maybe (Result ('Spec labels necessity dbType a))
unnullifier HNullify t (H Result)
hleft
a
IsRight -> Either (t (H Result)) (u (H Result))
-> (u (H Result) -> Either (t (H Result)) (u (H Result)))
-> Maybe (u (H Result))
-> Either (t (H Result)) (u (H Result))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either (t (H Result)) (u (H Result))
forall a. a
err u (H Result) -> Either (t (H Result)) (u (H Result))
forall a b. b -> Either a b
Right (Maybe (u (H Result)) -> Either (t (H Result)) (u (H Result)))
-> Maybe (u (H Result)) -> Either (t (H Result)) (u (H Result))
forall a b. (a -> b) -> a -> b
$ (forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
-> Maybe (Result ('Spec labels necessity dbType a)))
-> HNullify u (H Result) -> Maybe (u (H Result))
forall (t :: HKTable) (m :: * -> *) (context :: Spec -> *).
(HTable t, Apply m) =>
(forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType (Maybe dbType))
-> m (context ('Spec labels necessity dbType a)))
-> HNullify t (H context) -> m (t (H context))
hunnullify forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
-> Maybe (Result ('Spec labels necessity dbType a))
unnullifier HNullify u (H Result)
hright
where
err :: a
err = [Char] -> a
forall a. HasCallStack => [Char] -> a
error [Char]
"fromHEitherTable: mismatch between tag and data"
{-# INLINABLE fromHEitherTable #-}
toHListTable :: HTable t => [t (H Result)] -> HListTable t (H Result)
toHListTable :: [t (H Result)] -> HListTable t (H Result)
toHListTable = (forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> [Result ('Spec labels necessity db a)]
-> Result ('Spec labels necessity [a] [a]))
-> [t (H Result)] -> HListTable t (H Result)
forall (t :: HKTable) (f :: * -> *) (context :: Spec -> *)
(context' :: Spec -> *) (list :: * -> *).
(HTable t, Unzip f) =>
(forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> f (context ('Spec labels necessity db a))
-> context' ('Spec labels necessity (list a) (list a)))
-> f (t (H context)) -> HVectorize list t (H context')
hvectorize forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> [Result ('Spec labels necessity db a)]
-> Result ('Spec labels necessity [a] [a])
forall (f :: * -> *) (labels :: Labels) (necessity :: Necessity) db
a.
Functor f =>
SSpec ('Spec labels necessity db a)
-> f (Result ('Spec labels necessity db a))
-> Result ('Spec labels necessity (f a) (f a))
vectorizer
{-# INLINABLE toHListTable #-}
fromHListTable :: HTable t => HListTable t (H Result) -> [t (H Result)]
fromHListTable :: HListTable t (H Result) -> [t (H Result)]
fromHListTable = (forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity [a] [a])
-> [Result ('Spec labels necessity db a)])
-> HListTable t (H Result) -> [t (H Result)]
forall (t :: HKTable) (f :: * -> *) (context :: Spec -> *)
(list :: * -> *) (context' :: Spec -> *).
(HTable t, Repeat f) =>
(forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> context ('Spec labels necessity (list a) (list a))
-> f (context' ('Spec labels necessity db a)))
-> HVectorize list t (H context) -> f (t (H context'))
hunvectorize forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity [a] [a])
-> [Result ('Spec labels necessity db a)]
forall (f :: * -> *) (labels :: Labels) (necessity :: Necessity) db
a.
Functor f =>
SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity (f a) (f a))
-> f (Result ('Spec labels necessity db a))
unvectorizer
{-# INLINABLE fromHListTable #-}
toHMaybeTable :: HTable t => Maybe (t (H Result)) -> HMaybeTable t (H Result)
toHMaybeTable :: Maybe (t (H Result)) -> HMaybeTable t (H Result)
toHMaybeTable = HMaybeTable t (H Result)
-> (t (H Result) -> HMaybeTable t (H Result))
-> Maybe (t (H Result))
-> HMaybeTable t (H Result)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe HMaybeTable t (H Result)
hnothing t (H Result) -> HMaybeTable t (H Result)
forall (table :: HKTable).
HTable table =>
table (H Result) -> HMaybeTable table (H Result)
hjust
where
hnothing :: HMaybeTable t (H Result)
hnothing = HMaybeTable :: forall (table :: HKTable) (context :: HContext).
HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) context
-> HNullify table context -> HMaybeTable table context
HMaybeTable
{ htag :: HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
htag = Result ('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag))
-> HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
forall (context :: Spec -> *) (spec :: Spec).
context spec -> HIdentity spec (H context)
HIdentity (Maybe MaybeTag
-> Result ('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag))
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result Maybe MaybeTag
forall a. Maybe a
Nothing)
, hjust :: HNullify t (H Result)
hjust = (forall (labels :: Labels) (necessity :: Necessity) dbType.
Result ('Spec labels necessity dbType (Maybe dbType)))
-> HNullify t (H Result)
forall (t :: HKTable) (context :: Spec -> *).
HTable t =>
(forall (labels :: Labels) (necessity :: Necessity) dbType.
context ('Spec labels necessity dbType (Maybe dbType)))
-> HNullify t (H context)
hnulls forall (labels :: Labels) (necessity :: Necessity) dbType.
Result ('Spec labels necessity dbType (Maybe dbType))
null
}
hjust :: table (H Result) -> HMaybeTable table (H Result)
hjust table (H Result)
table = HMaybeTable :: forall (table :: HKTable) (context :: HContext).
HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) context
-> HNullify table context -> HMaybeTable table context
HMaybeTable
{ htag :: HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
htag = Result ('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag))
-> HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
forall (context :: Spec -> *) (spec :: Spec).
context spec -> HIdentity spec (H context)
HIdentity (Maybe MaybeTag
-> Result ('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag))
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result (MaybeTag -> Maybe MaybeTag
forall a. a -> Maybe a
Just MaybeTag
IsJust))
, hjust :: HNullify table (H Result)
hjust = (forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType)))
-> table (H Result) -> HNullify table (H Result)
forall (t :: HKTable) (context :: Spec -> *).
HTable t =>
(forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType (Maybe dbType)))
-> t (H context) -> HNullify t (H context)
hnullify forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
nullifier table (H Result)
table
}
{-# INLINABLE toHMaybeTable #-}
fromHMaybeTable :: HTable t => HMaybeTable t (H Result) -> Maybe (t (H Result))
fromHMaybeTable :: HMaybeTable t (H Result) -> Maybe (t (H Result))
fromHMaybeTable HMaybeTable {HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
htag :: HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
htag :: forall (table :: HKTable) (context :: HContext).
HMaybeTable table context
-> HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) context
htag, HNullify t (H Result)
hjust :: HNullify t (H Result)
hjust :: forall (table :: HKTable) (context :: HContext).
HMaybeTable table context -> HNullify table context
hjust} = case HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
htag of
HIdentity (Result tag) -> a
Maybe MaybeTag
tag Maybe MaybeTag -> t (H Result) -> Maybe (t (H Result))
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$>
case (forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
-> Maybe (Result ('Spec labels necessity dbType a)))
-> HNullify t (H Result) -> Maybe (t (H Result))
forall (t :: HKTable) (m :: * -> *) (context :: Spec -> *).
(HTable t, Apply m) =>
(forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> context ('Spec labels necessity dbType (Maybe dbType))
-> m (context ('Spec labels necessity dbType a)))
-> HNullify t (H context) -> m (t (H context))
hunnullify forall (labels :: Labels) (necessity :: Necessity) dbType a.
SSpec ('Spec labels necessity dbType a)
-> Result ('Spec labels necessity dbType (Maybe dbType))
-> Maybe (Result ('Spec labels necessity dbType a))
unnullifier HNullify t (H Result)
hjust of
Maybe (t (H Result))
Nothing -> [Char] -> t (H Result)
forall a. HasCallStack => [Char] -> a
error [Char]
"fromHMaybeTable: mismatch between tag and data"
Just t (H Result)
just -> t (H Result)
just
{-# INLINABLE fromHMaybeTable #-}
toHNonEmptyTable :: HTable t => NonEmpty (t (H Result)) -> HNonEmptyTable t (H Result)
toHNonEmptyTable :: NonEmpty (t (H Result)) -> HNonEmptyTable t (H Result)
toHNonEmptyTable = (forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> NonEmpty (Result ('Spec labels necessity db a))
-> Result ('Spec labels necessity (NonEmpty a) (NonEmpty a)))
-> NonEmpty (t (H Result)) -> HNonEmptyTable t (H Result)
forall (t :: HKTable) (f :: * -> *) (context :: Spec -> *)
(context' :: Spec -> *) (list :: * -> *).
(HTable t, Unzip f) =>
(forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> f (context ('Spec labels necessity db a))
-> context' ('Spec labels necessity (list a) (list a)))
-> f (t (H context)) -> HVectorize list t (H context')
hvectorize forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> NonEmpty (Result ('Spec labels necessity db a))
-> Result ('Spec labels necessity (NonEmpty a) (NonEmpty a))
forall (f :: * -> *) (labels :: Labels) (necessity :: Necessity) db
a.
Functor f =>
SSpec ('Spec labels necessity db a)
-> f (Result ('Spec labels necessity db a))
-> Result ('Spec labels necessity (f a) (f a))
vectorizer
{-# INLINABLE toHNonEmptyTable #-}
fromHNonEmptyTable :: HTable t => HNonEmptyTable t (H Result) -> NonEmpty (t (H Result))
fromHNonEmptyTable :: HNonEmptyTable t (H Result) -> NonEmpty (t (H Result))
fromHNonEmptyTable = (forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity (NonEmpty a) (NonEmpty a))
-> NonEmpty (Result ('Spec labels necessity db a)))
-> HNonEmptyTable t (H Result) -> NonEmpty (t (H Result))
forall (t :: HKTable) (f :: * -> *) (context :: Spec -> *)
(list :: * -> *) (context' :: Spec -> *).
(HTable t, Repeat f) =>
(forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> context ('Spec labels necessity (list a) (list a))
-> f (context' ('Spec labels necessity db a)))
-> HVectorize list t (H context) -> f (t (H context'))
hunvectorize forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity (NonEmpty a) (NonEmpty a))
-> NonEmpty (Result ('Spec labels necessity db a))
forall (f :: * -> *) (labels :: Labels) (necessity :: Necessity) db
a.
Functor f =>
SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity (f a) (f a))
-> f (Result ('Spec labels necessity db a))
unvectorizer
{-# INLINABLE fromHNonEmptyTable #-}
toHTheseTable :: (HTable t, HTable u)
=> These (t (H Result)) (u (H Result))
-> HTheseTable t u (H Result)
toHTheseTable :: These (t (H Result)) (u (H Result)) -> HTheseTable t u (H Result)
toHTheseTable These (t (H Result)) (u (H Result))
tables = HTheseTable :: forall (here :: HKTable) (there :: HKTable) (context :: HContext).
HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) context
-> HNullify here context
-> HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag)) context
-> HNullify there context
-> HTheseTable here there context
HTheseTable
{ hhereTag :: HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hhereTag = HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
-> HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
forall (labels :: Labels) (necessity :: Necessity) db a
(relabels :: Labels).
HIdentity ('Spec labels necessity db a) (H Result)
-> HIdentity ('Spec relabels necessity db a) (H Result)
relabel HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hhereTag
, HNullify t (H Result)
hhere :: HNullify t (H Result)
hhere :: HNullify t (H Result)
hhere
, hthereTag :: HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag))
(H Result)
hthereTag = HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
-> HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag))
(H Result)
forall (labels :: Labels) (necessity :: Necessity) db a
(relabels :: Labels).
HIdentity ('Spec labels necessity db a) (H Result)
-> HIdentity ('Spec relabels necessity db a) (H Result)
relabel HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hthereTag
, HNullify u (H Result)
hthere :: HNullify u (H Result)
hthere :: HNullify u (H Result)
hthere
}
where
HMaybeTable
{ htag :: forall (table :: HKTable) (context :: HContext).
HMaybeTable table context
-> HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) context
htag = HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hhereTag
, hjust :: forall (table :: HKTable) (context :: HContext).
HMaybeTable table context -> HNullify table context
hjust = HNullify t (H Result)
hhere
} = Maybe (t (H Result)) -> HMaybeTable t (H Result)
forall (t :: HKTable).
HTable t =>
Maybe (t (H Result)) -> HMaybeTable t (H Result)
toHMaybeTable (These (t (H Result)) (u (H Result)) -> Maybe (t (H Result))
forall a b. These a b -> Maybe a
justHere These (t (H Result)) (u (H Result))
tables)
HMaybeTable
{ htag :: forall (table :: HKTable) (context :: HContext).
HMaybeTable table context
-> HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) context
htag = HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hthereTag
, hjust :: forall (table :: HKTable) (context :: HContext).
HMaybeTable table context -> HNullify table context
hjust = HNullify u (H Result)
hthere
} = Maybe (u (H Result)) -> HMaybeTable u (H Result)
forall (t :: HKTable).
HTable t =>
Maybe (t (H Result)) -> HMaybeTable t (H Result)
toHMaybeTable (These (t (H Result)) (u (H Result)) -> Maybe (u (H Result))
forall a b. These a b -> Maybe b
justThere These (t (H Result)) (u (H Result))
tables)
{-# INLINABLE toHTheseTable #-}
fromHTheseTable :: (HTable t, HTable u)
=> HTheseTable t u (H Result)
-> These (t (H Result)) (u (H Result))
fromHTheseTable :: HTheseTable t u (H Result) -> These (t (H Result)) (u (H Result))
fromHTheseTable HTheseTable {HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hhereTag :: HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hhereTag :: forall (here :: HKTable) (there :: HKTable) (context :: HContext).
HTheseTable here there context
-> HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) context
hhereTag, HNullify t (H Result)
hhere :: HNullify t (H Result)
hhere :: forall (here :: HKTable) (there :: HKTable) (context :: HContext).
HTheseTable here there context -> HNullify here context
hhere, HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag))
(H Result)
hthereTag :: HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag))
(H Result)
hthereTag :: forall (here :: HKTable) (there :: HKTable) (context :: HContext).
HTheseTable here there context
-> HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag)) context
hthereTag, HNullify u (H Result)
hthere :: HNullify u (H Result)
hthere :: forall (here :: HKTable) (there :: HKTable) (context :: HContext).
HTheseTable here there context -> HNullify there context
hthere} =
case (HMaybeTable t (H Result) -> Maybe (t (H Result))
forall (t :: HKTable).
HTable t =>
HMaybeTable t (H Result) -> Maybe (t (H Result))
fromHMaybeTable HMaybeTable t (H Result)
mhere, HMaybeTable u (H Result) -> Maybe (u (H Result))
forall (t :: HKTable).
HTable t =>
HMaybeTable t (H Result) -> Maybe (t (H Result))
fromHMaybeTable HMaybeTable u (H Result)
mthere) of
(Just t (H Result)
a, Maybe (u (H Result))
Nothing) -> t (H Result) -> These (t (H Result)) (u (H Result))
forall a b. a -> These a b
This t (H Result)
a
(Maybe (t (H Result))
Nothing, Just u (H Result)
b) -> u (H Result) -> These (t (H Result)) (u (H Result))
forall a b. b -> These a b
That u (H Result)
b
(Just t (H Result)
a, Just u (H Result)
b) -> t (H Result) -> u (H Result) -> These (t (H Result)) (u (H Result))
forall a b. a -> b -> These a b
These t (H Result)
a u (H Result)
b
(Maybe (t (H Result)), Maybe (u (H Result)))
_ -> [Char] -> These (t (H Result)) (u (H Result))
forall a. HasCallStack => [Char] -> a
error [Char]
"fromHTheseTable: mismatch between tags and data"
where
mhere :: HMaybeTable t (H Result)
mhere = HMaybeTable :: forall (table :: HKTable) (context :: HContext).
HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) context
-> HNullify table context -> HMaybeTable table context
HMaybeTable
{ htag :: HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
htag = HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
-> HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
forall (labels :: Labels) (necessity :: Necessity) db a
(relabels :: Labels).
HIdentity ('Spec labels necessity db a) (H Result)
-> HIdentity ('Spec relabels necessity db a) (H Result)
relabel HIdentity
('Spec '["hasHere"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
hhereTag
, hjust :: HNullify t (H Result)
hjust = HNullify t (H Result)
hhere
}
mthere :: HMaybeTable u (H Result)
mthere = HMaybeTable :: forall (table :: HKTable) (context :: HContext).
HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) context
-> HNullify table context -> HMaybeTable table context
HMaybeTable
{ htag :: HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
htag = HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag))
(H Result)
-> HIdentity
('Spec '["isJust"] 'Required MaybeTag (Maybe MaybeTag)) (H Result)
forall (labels :: Labels) (necessity :: Necessity) db a
(relabels :: Labels).
HIdentity ('Spec labels necessity db a) (H Result)
-> HIdentity ('Spec relabels necessity db a) (H Result)
relabel HIdentity
('Spec '["hasThere"] 'Required MaybeTag (Maybe MaybeTag))
(H Result)
hthereTag
, hjust :: HNullify u (H Result)
hjust = HNullify u (H Result)
hthere
}
{-# INLINABLE fromHTheseTable #-}
null :: Result ('Spec labels necessity db (Maybe db))
null :: Result ('Spec labels necessity db (Maybe db))
null = Maybe db -> Result ('Spec labels necessity db (Maybe db))
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result Maybe db
forall a. Maybe a
Nothing
nullifier :: ()
=> SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity db a)
-> Result ('Spec labels necessity db (Maybe db))
nullifier :: SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity db a)
-> Result ('Spec labels necessity db (Maybe db))
nullifier SSpec {Nullability db a
nullability :: forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a) -> Nullability db a
nullability :: Nullability db a
nullability} (Result a
a) = Maybe db -> Result ('Spec labels necessity db (Maybe db))
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result (Maybe db -> Result ('Spec labels necessity db (Maybe db)))
-> Maybe db -> Result ('Spec labels necessity db (Maybe db))
forall a b. (a -> b) -> a -> b
$ case Nullability db a
nullability of
Nullability db a
Nullable -> a
Maybe db
a
Nullability db a
NonNullable -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
unnullifier :: ()
=> SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity db (Maybe db))
-> Maybe (Result ('Spec labels necessity db a))
unnullifier :: SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity db (Maybe db))
-> Maybe (Result ('Spec labels necessity db a))
unnullifier SSpec {Nullability db a
nullability :: Nullability db a
nullability :: forall (labels :: Labels) (necessity :: Necessity) db a.
SSpec ('Spec labels necessity db a) -> Nullability db a
nullability} (Result a
a) =
case Nullability db a
nullability of
Nullability db a
Nullable -> Result ('Spec labels necessity db a)
-> Maybe (Result ('Spec labels necessity db a))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Result ('Spec labels necessity db a)
-> Maybe (Result ('Spec labels necessity db a)))
-> Result ('Spec labels necessity db a)
-> Maybe (Result ('Spec labels necessity db a))
forall a b. (a -> b) -> a -> b
$ a -> Result ('Spec labels necessity db a)
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result a
a
Nullability db a
NonNullable -> a -> Result ('Spec labels necessity db a)
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result (a -> Result ('Spec labels necessity db a))
-> Maybe a -> Maybe (Result ('Spec labels necessity db a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a
Maybe a
a
vectorizer :: Functor f
=> SSpec ('Spec labels necessity db a)
-> f (Result ('Spec labels necessity db a))
-> Result ('Spec labels necessity (f a) (f a))
vectorizer :: SSpec ('Spec labels necessity db a)
-> f (Result ('Spec labels necessity db a))
-> Result ('Spec labels necessity (f a) (f a))
vectorizer SSpec ('Spec labels necessity db a)
_ = f a -> Result ('Spec labels necessity (f a) (f a))
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result (f a -> Result ('Spec labels necessity (f a) (f a)))
-> (f (Result ('Spec labels necessity db a)) -> f a)
-> f (Result ('Spec labels necessity db a))
-> Result ('Spec labels necessity (f a) (f a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Result ('Spec labels necessity db a) -> a)
-> f (Result ('Spec labels necessity db a)) -> f a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(Result a
a) -> a
a
a)
unvectorizer :: Functor f
=> SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity (f a) (f a))
-> f (Result ('Spec labels necessity db a))
unvectorizer :: SSpec ('Spec labels necessity db a)
-> Result ('Spec labels necessity (f a) (f a))
-> f (Result ('Spec labels necessity db a))
unvectorizer SSpec ('Spec labels necessity db a)
_ (Result a
results) = a -> Result ('Spec labels necessity db a)
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result (a -> Result ('Spec labels necessity db a))
-> f a -> f (Result ('Spec labels necessity db a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a
f a
results
relabel :: ()
=> HIdentity ('Spec labels necessity db a) (H Result)
-> HIdentity ('Spec relabels necessity db a) (H Result)
relabel :: HIdentity ('Spec labels necessity db a) (H Result)
-> HIdentity ('Spec relabels necessity db a) (H Result)
relabel (HIdentity (Result a)) = Result ('Spec relabels necessity db a)
-> HIdentity ('Spec relabels necessity db a) (H Result)
forall (context :: Spec -> *) (spec :: Spec).
context spec -> HIdentity spec (H context)
HIdentity (a -> Result ('Spec relabels necessity db a)
forall a (labels :: Labels) (necessity :: Necessity) dbType.
a -> Result ('Spec labels necessity dbType a)
Result a
a)