{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
module Frames.Aggregation.Maybe
(
RecordKeyMap
, combineKeyAggregations
, keyMap
, aggregateAllFold
, aggregateFold
, mergeDataFolds
)
where
import Frames.MapReduce.General ( RecGetFieldC(..)
, RCastC(..)
, IsoRec(..)
)
import qualified Frames.Aggregation.General as FA
import Frames.Aggregation.General ( RecordKeyMap )
import qualified Frames as F
import Frames ( (:.) )
import qualified Frames.Melt as F
import qualified Data.Vinyl as V
import Data.Vinyl ( ElField )
import qualified Data.Vinyl.TypeLevel as V
import qualified Control.Foldl as FL
import GHC.TypeLits ( Symbol )
import Data.Kind ( Type )
combineKeyAggregations
:: forall (a :: [(Symbol, Type)]) b a' b' record
. ( a F.⊆ (a V.++ b)
, b F.⊆ (a V.++ b)
, F.Disjoint a' b' ~ 'True
, RCastC a (a V.++ b) record Maybe
, RCastC b (a V.++ b) record Maybe
, IsoRec a' record Maybe
, IsoRec b' record Maybe
, IsoRec (a' V.++ b') record Maybe
)
=> RecordKeyMap record Maybe a a'
-> RecordKeyMap record Maybe b b'
-> RecordKeyMap record Maybe (a V.++ b) (a' V.++ b')
combineKeyAggregations :: RecordKeyMap record Maybe a a'
-> RecordKeyMap record Maybe b b'
-> RecordKeyMap record Maybe (a ++ b) (a' ++ b')
combineKeyAggregations = RecordKeyMap record Maybe a a'
-> RecordKeyMap record Maybe b b'
-> RecordKeyMap record Maybe (a ++ b) (a' ++ b')
forall (a :: [(Symbol, *)]) (b :: [(Symbol, *)])
(a' :: [(Symbol, *)]) (b' :: [(Symbol, *)])
(record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) (f :: * -> *).
(a ⊆ (a ++ b), b ⊆ (a ++ b), Disjoint a' b' ~ 'True,
RCastC a (a ++ b) record f, RCastC b (a ++ b) record f,
IsoRec a' record f, IsoRec b' record f,
IsoRec (a' ++ b') record f) =>
RecordKeyMap record f a a'
-> RecordKeyMap record f b b'
-> RecordKeyMap record f (a ++ b) (a' ++ b')
FA.combineKeyAggregations
keyMap
:: forall a b record
. ( V.KnownField a
, V.KnownField b
, RecGetFieldC a record Maybe '[a]
, IsoRec '[b] record Maybe
, Applicative Maybe
)
=> (V.Snd a -> V.Snd b)
-> RecordKeyMap record Maybe '[a] '[b]
keyMap :: (Snd a -> Snd b) -> RecordKeyMap record Maybe '[a] '[b]
keyMap = (Snd a -> Snd b) -> RecordKeyMap record Maybe '[a] '[b]
forall (a :: (Symbol, *)) (b :: (Symbol, *))
(record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) (f :: * -> *).
(KnownField a, KnownField b, RecGetFieldC a record f '[a],
IsoRec '[b] record f, Applicative f) =>
(Snd a -> Snd b) -> RecordKeyMap record f '[a] '[b]
FA.keyMap
aggregateAllFold
:: forall (ak :: [(Symbol, Type)]) ak' d record
. ( (ak' V.++ d) F.⊆ ((ak V.++ d) V.++ ak')
, ak F.⊆ (ak V.++ d)
, ak' F.⊆ (ak' V.++ d)
, d F.⊆ (ak' V.++ d)
, Ord (record (Maybe :. ElField) ak')
, Ord (record (Maybe :. ElField) ak)
, RCastC (ak' V.++ d) ((ak V.++ d) V.++ ak') record Maybe
, RCastC ak (ak V.++ d) record Maybe
, RCastC ak' (ak' V.++ d) record Maybe
, RCastC d (ak' V.++ d) record Maybe
, IsoRec d record Maybe
, IsoRec (ak V.++ d) record Maybe
, IsoRec (ak' V.++ d) record Maybe
, IsoRec ak' record Maybe
, IsoRec ((ak V.++ d) V.++ ak') record Maybe
)
=> RecordKeyMap record Maybe ak ak'
-> (FL.Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) d))
-> FL.Fold
(record (Maybe :. ElField) (ak V.++ d))
[(record (Maybe :. ElField) (ak' V.++ d))]
aggregateAllFold :: RecordKeyMap record Maybe ak ak'
-> Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) d)
-> Fold
(record (Maybe :. ElField) (ak ++ d))
[record (Maybe :. ElField) (ak' ++ d)]
aggregateAllFold = RecordKeyMap record Maybe ak ak'
-> Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) d)
-> Fold
(record (Maybe :. ElField) (ak ++ d))
[record (Maybe :. ElField) (ak' ++ d)]
forall (ak :: [(Symbol, *)]) (ak' :: [(Symbol, *)])
(d :: [(Symbol, *)])
(record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) (f :: * -> *).
((ak' ++ d) ⊆ ((ak ++ d) ++ ak'), ak ⊆ (ak ++ d), ak' ⊆ (ak' ++ d),
d ⊆ (ak' ++ d), Ord (record (f :. ElField) ak'),
Ord (record (f :. ElField) ak),
RCastC (ak' ++ d) ((ak ++ d) ++ ak') record f,
RCastC ak (ak ++ d) record f, RCastC ak' (ak' ++ d) record f,
RCastC d (ak' ++ d) record f, IsoRec d record f,
IsoRec (ak ++ d) record f, IsoRec (ak' ++ d) record f,
IsoRec ak' record f, IsoRec ((ak ++ d) ++ ak') record f) =>
RecordKeyMap record f ak ak'
-> Fold (record (f :. ElField) d) (record (f :. ElField) d)
-> Fold
(record (f :. ElField) (ak ++ d))
[record (f :. ElField) (ak' ++ d)]
FA.aggregateAllFold
aggregateFold
:: forall (k :: [(Symbol, Type)]) ak ak' d record
. ( (ak' V.++ d) F.⊆ ((ak V.++ d) V.++ ak')
, ak F.⊆ (ak V.++ d)
, ak' F.⊆ (ak' V.++ d)
, d F.⊆ (ak' V.++ d)
, Ord (record (Maybe :. ElField) ak')
, Ord (record (Maybe :. ElField) ak)
, (k V.++ (ak' V.++ d)) ~ ((k V.++ ak') V.++ d)
, Ord (record (Maybe :. ElField) k)
, k F.⊆ ((k V.++ ak') V.++ d)
, k F.⊆ ((k V.++ ak) V.++ d)
, (ak V.++ d) F.⊆ ((k V.++ ak) V.++ d)
, RCastC ak (ak V.++ d) record Maybe
, RCastC ak' (ak' V.++ d) record Maybe
, RCastC d (ak' V.++ d) record Maybe
, RCastC k ((k V.++ ak) V.++ d) record Maybe
, RCastC (ak V.++ d) ((k V.++ ak) V.++ d) record Maybe
, RCastC (ak' V.++ d) ((ak V.++ d) V.++ ak') record Maybe
, IsoRec k record Maybe
, IsoRec d record Maybe
, IsoRec ((k V.++ ak') V.++ d) record Maybe
, IsoRec (ak V.++ d) record Maybe
, IsoRec (ak' V.++ d) record Maybe
, IsoRec ak' record Maybe
, IsoRec ((ak V.++ d) V.++ ak') record Maybe
)
=> RecordKeyMap record Maybe ak ak'
-> (FL.Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) d))
-> FL.Fold
(record (Maybe :. ElField) (k V.++ ak V.++ d))
[record (Maybe :. ElField) (k V.++ ak' V.++ d)]
aggregateFold :: RecordKeyMap record Maybe ak ak'
-> Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) d)
-> Fold
(record (Maybe :. ElField) ((k ++ ak) ++ d))
[record (Maybe :. ElField) ((k ++ ak') ++ d)]
aggregateFold = forall (k :: [(Symbol, *)]) (ak :: [(Symbol, *)])
(ak' :: [(Symbol, *)]) (d :: [(Symbol, *)])
(record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) (f :: * -> *).
((ak' ++ d) ⊆ ((ak ++ d) ++ ak'), ak ⊆ (ak ++ d), ak' ⊆ (ak' ++ d),
d ⊆ (ak' ++ d), Ord (record (f :. ElField) ak'),
Ord (record (f :. ElField) ak),
(k ++ (ak' ++ d)) ~ ((k ++ ak') ++ d),
Ord (record (f :. ElField) k), k ⊆ ((k ++ ak') ++ d),
k ⊆ ((k ++ ak) ++ d), (ak ++ d) ⊆ ((k ++ ak) ++ d),
RCastC ak (ak ++ d) record f, RCastC ak' (ak' ++ d) record f,
RCastC d (ak' ++ d) record f, RCastC k ((k ++ ak) ++ d) record f,
RCastC (ak ++ d) ((k ++ ak) ++ d) record f,
RCastC (ak' ++ d) ((ak ++ d) ++ ak') record f, IsoRec k record f,
IsoRec d record f, IsoRec ((k ++ ak') ++ d) record f,
IsoRec (ak ++ d) record f, IsoRec (ak' ++ d) record f,
IsoRec ak' record f, IsoRec ((ak ++ d) ++ ak') record f) =>
RecordKeyMap record f ak ak'
-> Fold (record (f :. ElField) d) (record (f :. ElField) d)
-> Fold
(record (f :. ElField) ((k ++ ak) ++ d))
[record (f :. ElField) ((k ++ ak') ++ d)]
forall (ak :: [(Symbol, *)]) (ak' :: [(Symbol, *)])
(d :: [(Symbol, *)])
(record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) (f :: * -> *).
((ak' ++ d) ⊆ ((ak ++ d) ++ ak'), ak ⊆ (ak ++ d), ak' ⊆ (ak' ++ d),
d ⊆ (ak' ++ d), Ord (record (f :. ElField) ak'),
Ord (record (f :. ElField) ak),
(k ++ (ak' ++ d)) ~ ((k ++ ak') ++ d),
Ord (record (f :. ElField) k), k ⊆ ((k ++ ak') ++ d),
k ⊆ ((k ++ ak) ++ d), (ak ++ d) ⊆ ((k ++ ak) ++ d),
RCastC ak (ak ++ d) record f, RCastC ak' (ak' ++ d) record f,
RCastC d (ak' ++ d) record f, RCastC k ((k ++ ak) ++ d) record f,
RCastC (ak ++ d) ((k ++ ak) ++ d) record f,
RCastC (ak' ++ d) ((ak ++ d) ++ ak') record f, IsoRec k record f,
IsoRec d record f, IsoRec ((k ++ ak') ++ d) record f,
IsoRec (ak ++ d) record f, IsoRec (ak' ++ d) record f,
IsoRec ak' record f, IsoRec ((ak ++ d) ++ ak') record f) =>
RecordKeyMap record f ak ak'
-> Fold (record (f :. ElField) d) (record (f :. ElField) d)
-> Fold
(record (f :. ElField) ((k ++ ak) ++ d))
[record (f :. ElField) ((k ++ ak') ++ d)]
FA.aggregateFold @k
mergeDataFolds
:: forall (a :: (Symbol, Type)) b d record
. ( IsoRec '[b] record Maybe
, IsoRec '[a] record Maybe
, IsoRec '[a, b] record Maybe
)
=> FL.Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) '[a])
-> FL.Fold
(record (Maybe :. ElField) d)
(record (Maybe :. ElField) '[b])
-> FL.Fold
(record (Maybe :. ElField) d)
(record (Maybe :. ElField) '[a, b])
mergeDataFolds :: Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) '[a])
-> Fold
(record (Maybe :. ElField) d) (record (Maybe :. ElField) '[b])
-> Fold
(record (Maybe :. ElField) d) (record (Maybe :. ElField) '[a, b])
mergeDataFolds = Fold (record (Maybe :. ElField) d) (record (Maybe :. ElField) '[a])
-> Fold
(record (Maybe :. ElField) d) (record (Maybe :. ElField) '[b])
-> Fold
(record (Maybe :. ElField) d) (record (Maybe :. ElField) '[a, b])
forall (a :: (Symbol, *)) (b :: (Symbol, *)) (d :: [(Symbol, *)])
(record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) (f :: * -> *).
(IsoRec '[b] record f, IsoRec '[a] record f,
IsoRec '[a, b] record f) =>
Fold (record (f :. ElField) d) (record (f :. ElField) '[a])
-> Fold (record (f :. ElField) d) (record (f :. ElField) '[b])
-> Fold (record (f :. ElField) d) (record (f :. ElField) '[a, b])
FA.mergeDataFolds