@@ -60,18 +60,28 @@ getQueryTLoweredResultValue (QueryTLoweredResult (v, _)) = v
60getQueryTLoweredResultWritten :: QueryTLoweredResult t q v -> [Behavior t q]
60getQueryTLoweredResultWritten :: QueryTLoweredResult t q v -> [Behavior t q]
61getQueryTLoweredResultWritten (QueryTLoweredResult (_, w)) = w
61getQueryTLoweredResultWritten (QueryTLoweredResult (_, w)) = w
64+let sampleBs :: forall m'. MonadSample t m' => [Behavior t q] -> m' q
65+ sampleBs = foldlM (\b a -> (b <>) <$> sample a) mempty
66+ bs' = fmapCheap snd $ r'
67+ patches = unsafeBuildIncremental (sampleBs bs0) $
68+ flip pushCheap bs' $ \bs -> do
69+ p <- (~~) <$> sampleBs bs <*> sample (currentIncremental patches)
70+ return (Just (AdditivePatch p))
63instance (Reflex t, MonadFix m, Group q, Additive q, Query q, MonadHold t m, MonadAdjust t m) => MonadAdjust t (QueryT t q m) where
73instance (Reflex t, MonadFix m, Group q, Additive q, Query q, MonadHold t m, MonadAdjust t m) => MonadAdjust t (QueryT t q m) where
64 runWithReplace (QueryT a0) a' = do
74 runWithReplace (QueryT a0) a' = do
65 ((r0, bs0), r') <- QueryT $ lift $ runWithReplace (runStateT a0 []) $ fmapCheap (flip runStateT [] . unQueryT) a'
75 ((r0, bs0), r') <- QueryT $ lift $ runWithReplace (runStateT a0 []) $ fmapCheap (flip runStateT [] . unQueryT) a'
66− tellQueryIncremental $
67− let sampleBs :: forall m'. MonadSample t m' => [Behavior t q] -> m' q
76+ let sampleBs :: forall m'. MonadSample t m' => [Behavior t q] -> m' q
68− sampleBs = foldlM (\b a -> (b <>) <$> sample a) mempty
77+ sampleBs = foldlM (\b a -> (b <>) <$> sample a) mempty
69− bs' = fmapCheap snd $ r'
78+ bs' = fmapCheap snd $ r'
70− patches = unsafeBuildIncremental (sampleBs bs0) $
79+ bbs <- hold bs0 bs'
71− flip pushCheap bs' $ \bs -> do
80+ let patches = flip pushAlwaysCheap bs' $ \newBs -> do
72− p <- (~~) <$> sampleBs bs <*> sample (currentIncremental patches)
81+ oldBs <- sample bbs
73− return (Just (AdditivePatch p))
82+ (~~) <$> sampleBs newBs <*> sampleBs oldBs
83+ QueryT $ modify $ (:) $ pull $ sampleBs =<< sample bbs
74− in patches
84+ QueryT $ lift $ tellEvent patches
75 return (r0, fmapCheap fst r')
85 return (r0, fmapCheap fst r')
76 traverseDMapWithKeyWithAdjust :: forall (k :: * -> *) v v'. (DMap.GCompare k) => (forall a. k a -> v a -> QueryT t q m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> QueryT t q m (DMap k v', Event t (PatchDMap k v'))
86 traverseDMapWithKeyWithAdjust :: forall (k :: * -> *) v v'. (DMap.GCompare k) => (forall a. k a -> v a -> QueryT t q m (v' a)) -> DMap k v -> Event t (PatchDMap k v) -> QueryT t q m (DMap k v', Event t (PatchDMap k v'))
77 traverseDMapWithKeyWithAdjust f dm0 dm' = do
87 traverseDMapWithKeyWithAdjust f dm0 dm' = do