@@ -156,16 +156,22 @@ mapDynM f d = do
156-- time the 'Event' occurs using a folding function on the previous
156-- time the 'Event' occurs using a folding function on the previous
157-- value and the value of the 'Event'.
157-- value and the value of the 'Event'.
158foldDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> b) -> b -> Event t a -> m (Dynamic t b)
158foldDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> b) -> b -> Event t a -> m (Dynamic t b)
159−foldDyn f = foldDynM (\o v -> return $ f o v)
159+foldDyn f = foldDynMaybe $ \o v -> Just $ f o v
161-- | Create a 'Dynamic' using the initial value and change it each
161-- | Create a 'Dynamic' using the initial value and change it each
162-- time the 'Event' occurs using a monadic folding function on the
162-- time the 'Event' occurs using a monadic folding function on the
163-- previous value and the value of the 'Event'.
163-- previous value and the value of the 'Event'.
164foldDynM :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t b) -> b -> Event t a -> m (Dynamic t b)
164foldDynM :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t b) -> b -> Event t a -> m (Dynamic t b)
165−foldDynM f z e = do
165+foldDynM f = foldDynMaybeM $ \o v -> liftM Just $ f o v
167+foldDynMaybe :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe b) -> b -> Event t a -> m (Dynamic t b)
168+foldDynMaybe f = foldDynMaybeM $ \o v -> return $ f o v
170+foldDynMaybeM :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe b)) -> b -> Event t a -> m (Dynamic t b)
171+foldDynMaybeM f z e = do
166 rec let e' = flip push e $ \o -> do
172 rec let e' = flip push e $ \o -> do
167 v <- sample b'
173 v <- sample b'
168− liftM Just $ f o v
174+ f o v
169 b' <- hold z e'
175 b' <- hold z e'
170 return $ Dynamic b' e'
176 return $ Dynamic b' e'