@@ -80,6 +80,8 @@ module Reflex.Class
8080 , mapAccumMaybe_
8181 , mapAccumMaybeM_
8282 , zipListWithEvent
83+ , numberOccurrences
84+ , numberOccurrencesFrom
8385 , headE
8486 , tailE
8587 , headTailE
@@ -916,6 +918,14 @@ zipListWithEvent f l e = do
916918 _ -> (Nothing, Nothing) --TODO: Unsubscribe the event?
917919 mapAccumMaybe_ f' l e
918920
921+-- | Assign a number to each occurence of the given 'Event', starting from 0
922+numberOccurrences :: (Reflex t, MonadHold t m, MonadFix m, Num b) => Event t a -> m (Event t (b, a))
923+numberOccurrences = numberOccurrencesFrom 0
924+
925+-- | Assign a number to each occurence of the given 'Event'
926+numberOccurrencesFrom :: (Reflex t, MonadHold t m, MonadFix m, Num b) => b -> Event t a -> m (Event t (b, a))
927+numberOccurrencesFrom = mapAccum_ (\n a -> (n + 1, (n, a)))
928+
919929-- | A 'Monad' that supports adjustment over time. After an action has been
920930-- run, if the given events fire, it will adjust itself so that its net effect
921931-- is as though it had originally been run with the new value. Note that there