@@ -300,6 +300,8 @@ class ( MonadHold t (PushM t)
300 fanInt :: Event t (IntMap a) -> EventSelectorInt t a
300 fanInt :: Event t (IntMap a) -> EventSelectorInt t a
302--TODO: Specialize this so that we can take advantage of knowing that there's no changing going on
302--TODO: Specialize this so that we can take advantage of knowing that there's no changing going on
303+-- | Constructs a single 'Event' out of a map of events. The output event may fire with multiple
304+-- keys simultaneously.
303mergeInt :: Reflex t => IntMap (Event t a) -> Event t (IntMap a)
305mergeInt :: Reflex t => IntMap (Event t a) -> Event t (IntMap a)
304mergeInt m = mergeIntIncremental $ unsafeBuildIncremental (return m) never
306mergeInt m = mergeIntIncremental $ unsafeBuildIncremental (return m) never
@@ -368,26 +370,91 @@ class MonadSample t m => MonadHold t m where
368 -- the supplied 'Event'.
370 -- the supplied 'Event'.
369 headE :: Event t a -> m (Event t a)
371 headE :: Event t a -> m (Event t a)
373+-- | Accumulate an 'Incremental' with the supplied initial value and the firings of the provided 'Event',
374+-- using the combining function to produce a patch.
371−accumIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> p) -> PatchTarget p -> Event t b -> m (Incremental t p)
376+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
377+ => (PatchTarget p -> b -> p)
380+ -> m (Incremental t p)
372accumIncremental f = accumMaybeIncremental $ \v o -> Just $ f v o
381accumIncremental f = accumMaybeIncremental $ \v o -> Just $ f v o
383+-- | Similar to 'accumIncremental' but the combining function runs in 'PushM'
373−accumMIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> PushM t p) -> PatchTarget p -> Event t b -> m (Incremental t p)
385+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
386+ => (PatchTarget p -> b -> PushM t p)
389+ -> m (Incremental t p)
374accumMIncremental f = accumMaybeMIncremental $ \v o -> Just <$> f v o
390accumMIncremental f = accumMaybeMIncremental $ \v o -> Just <$> f v o
392+-- | Similar to 'accumIncremental' but allows filtering of updates (by dropping updates when the
393+-- combining function produces @Nothing@)
394+accumMaybeIncremental
375−accumMaybeIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> Maybe p) -> PatchTarget p -> Event t b -> m (Incremental t p)
395+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
396+ => (PatchTarget p -> b -> Maybe p)
399+ -> m (Incremental t p)
376accumMaybeIncremental f = accumMaybeMIncremental $ \v o -> return $ f v o
400accumMaybeIncremental f = accumMaybeMIncremental $ \v o -> return $ f v o
402+-- | Similar to 'accumMaybeMIncremental' but the combining function runs in 'PushM'
403+accumMaybeMIncremental
377−accumMaybeMIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> PushM t (Maybe p)) -> PatchTarget p -> Event t b -> m (Incremental t p)
404+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
405+ => (PatchTarget p -> b -> PushM t (Maybe p))
408+ -> m (Incremental t p)
378accumMaybeMIncremental f z e = do
409accumMaybeMIncremental f z e = do
379 rec let e' = flip push e $ \o -> do
410 rec let e' = flip push e $ \o -> do
380 v <- sample $ currentIncremental d'
411 v <- sample $ currentIncremental d'
382 d' <- holdIncremental z e'
413 d' <- holdIncremental z e'
383 return d'
414 return d'
416+-- | Accumulate an 'Incremental' by folding occurrences of an 'Event'
417+-- with a function that both accumulates and produces a value to fire
418+-- as an 'Event'. Returns both the accumulated value and the constructed
384−mapAccumIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> (p, c)) -> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
421+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
422+ => (PatchTarget p -> b -> (p, c))
425+ -> m (Incremental t p, Event t c)
385mapAccumIncremental f = mapAccumMaybeIncremental $ \v o -> bimap Just Just $ f v o
426mapAccumIncremental f = mapAccumMaybeIncremental $ \v o -> bimap Just Just $ f v o
428+-- | Like 'mapAccumIncremental' but the combining function runs in 'PushM'
386−mapAccumMIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> PushM t (p, c)) -> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
430+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
431+ => (PatchTarget p -> b -> PushM t (p, c))
434+ -> m (Incremental t p, Event t c)
387mapAccumMIncremental f = mapAccumMaybeMIncremental $ \v o -> bimap Just Just <$> f v o
435mapAccumMIncremental f = mapAccumMaybeMIncremental $ \v o -> bimap Just Just <$> f v o
437+-- | Accumulate an 'Incremental' by folding occurrences of an 'Event' with
438+-- a function that both optionally accumulates and optionally produces
439+-- a value to fire as a separate output 'Event'.
440+-- Note that because 'Nothing's are discarded in both cases, the output
441+-- 'Event' may fire even though the output 'Incremental' has not changed, and
442+-- the output 'Incremental' may update even when the output 'Event' is not firing.
443+mapAccumMaybeIncremental
388−mapAccumMaybeIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> (Maybe p, Maybe c)) -> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
444+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
445+ => (PatchTarget p -> b -> (Maybe p, Maybe c))
448+ -> m (Incremental t p, Event t c)
389mapAccumMaybeIncremental f = mapAccumMaybeMIncremental $ \v o -> return $ f v o
449mapAccumMaybeIncremental f = mapAccumMaybeMIncremental $ \v o -> return $ f v o
451+-- | Like 'mapAccumMaybeIncremental' but the combining function is a 'PushM' action
452+mapAccumMaybeMIncremental
390−mapAccumMaybeMIncremental :: (Reflex t, Patch p, MonadHold t m, MonadFix m) => (PatchTarget p -> b -> PushM t (Maybe p, Maybe c)) -> PatchTarget p -> Event t b -> m (Incremental t p, Event t c)
453+ :: (Reflex t, Patch p, MonadHold t m, MonadFix m)
454+ => (PatchTarget p -> b -> PushM t (Maybe p, Maybe c))
457+ -> m (Incremental t p, Event t c)
391mapAccumMaybeMIncremental f z e = do
458mapAccumMaybeMIncremental f z e = do
392 rec let e' = flip push e $ \o -> do
459 rec let e' = flip push e $ \o -> do
393 v <- sample $ currentIncremental d'
460 v <- sample $ currentIncremental d'
@@ -398,6 +465,7 @@ mapAccumMaybeMIncremental f z e = do
398 d' <- holdIncremental z $ mapMaybe fst e'
465 d' <- holdIncremental z $ mapMaybe fst e'
399 return (d', mapMaybe snd e')
466 return (d', mapMaybe snd e')
468+-- | A somewhat slow implementation of 'headE'
401slowHeadE :: (Reflex t, MonadHold t m, MonadFix m) => Event t a -> m (Event t a)
469slowHeadE :: (Reflex t, MonadHold t m, MonadFix m) => Event t a -> m (Event t a)
402slowHeadE e = do
470slowHeadE e = do
403 rec be <- hold e $ fmapCheap (const never) e'
471 rec be <- hold e $ fmapCheap (const never) e'
@@ -418,6 +486,8 @@ newtype EventSelector t k = EventSelector
418 select :: forall a. k a -> Event t a
486 select :: forall a. k a -> Event t a
489+-- | Efficiently select an 'Event' keyed on 'Int'. This is more efficient than manually
421newtype EventSelectorInt t a = EventSelectorInt { selectInt :: Int -> Event t a }
491newtype EventSelectorInt t a = EventSelectorInt { selectInt :: Int -> Event t a }
423--------------------------------------------------------------------------------
493--------------------------------------------------------------------------------
@@ -801,7 +871,12 @@ mergeList :: Reflex t => [Event t a] -> Event t (NonEmpty a)
801mergeList [] = never
871mergeList [] = never
802mergeList es = mergeWithFoldCheap' id es
872mergeList es = mergeWithFoldCheap' id es
875+ :: (Reflex t, Patch p, Patch p')
804−unsafeMapIncremental :: (Reflex t, Patch p, Patch p') => (PatchTarget p -> PatchTarget p') -> (p -> p') -> Incremental t p -> Incremental t p'
876+ => (PatchTarget p -> PatchTarget p')
805unsafeMapIncremental f g a = unsafeBuildIncremental (fmap f $ sample $ currentIncremental a) $ g <$> updatedIncremental a
880unsafeMapIncremental f g a = unsafeBuildIncremental (fmap f $ sample $ currentIncremental a) $ g <$> updatedIncremental a
807-- | Create a new 'Event' combining the map of 'Event's into an 'Event' that
882-- | Create a new 'Event' combining the map of 'Event's into an 'Event' that
@@ -918,6 +993,9 @@ coincidencePatchMapWithMove e = fmapCheap unsafePatchMapWithMove $ coincidence $
918 ni { PatchMapWithMove._nodeInfo_from = PatchMapWithMove.From_Delete }
993 ni { PatchMapWithMove._nodeInfo_from = PatchMapWithMove.From_Delete }
996+-- | Given a 'PatchTarget' of events (e.g., a 'Map' with 'Event' values) and an event of 'Patch'es
997+-- (e.g., a 'PatchMap' with 'Event' values), produce an 'Event' of the 'PatchTarget' type that
998+-- fires with the patched value.
921switchHoldPromptOnlyIncremental
999switchHoldPromptOnlyIncremental
922 :: forall t m p pt w
1000 :: forall t m p pt w
923 . ( Reflex t
1001 . ( Reflex t
@@ -1491,8 +1569,10 @@ mergeWithFoldCheap' f es =
1491--------------------------------------------------------------------------------
1569--------------------------------------------------------------------------------
1493{-# DEPRECATED switchPromptly "Use 'switchHoldPromptly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
1571{-# DEPRECATED switchPromptly "Use 'switchHoldPromptly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
1572+-- | See 'switchHoldPromptly'
1494switchPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
1573switchPromptly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
1495switchPromptly = switchHoldPromptly
1574switchPromptly = switchHoldPromptly
1496{-# DEPRECATED switchPromptOnly "Use 'switchHoldPromptOnly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
1575{-# DEPRECATED switchPromptOnly "Use 'switchHoldPromptOnly' instead. The 'switchHold*' naming convention was chosen because those functions are more closely related to each other than they are to 'switch'. " #-}
1576+-- | See 'switchHoldPromptOnly'
1497switchPromptOnly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
1577switchPromptOnly :: (Reflex t, MonadHold t m) => Event t a -> Event t (Event t a) -> m (Event t a)
1498switchPromptOnly = switchHoldPromptOnly
1578switchPromptOnly = switchHoldPromptOnly