on develop help sign in
Add improvingMaybe
commit8f2c9d413986ceb7c0bdb36f60add03efb247ee4 authorLuigy Leon <luigy@outlook.com> dateMon 22 May 2017, 17:32 (9 years ago) parent160e889
1 file changed+5
src/Reflex/Dynamic.hs+5
src/Reflex/Dynamic.hs+5
@@ -38,6 +38,7 @@ module Reflex.Dynamic
3838 , scanDynMaybe
3939 , holdUniqDyn
4040 , holdUniqDynBy
41+ , improvingMaybe
4142 , foldDyn
4243 , foldDynM
4344 , foldDynMaybe
@@ -116,6 +117,10 @@ holdUniqDyn = holdUniqDynBy (==)
116117holdUniqDynBy :: (Reflex t, MonadHold t m, MonadFix m) => (a -> a -> Bool) -> Dynamic t a -> m (Dynamic t a)
117118holdUniqDynBy eq = scanDynMaybe id (\new old -> if new `eq` old then Nothing else Just new)
118119
120+-- | Dynamic Maybe that can only update from Nothing to Just or Just to Just (i.e., cannot revert to Nothing)
121+improvingMaybe :: (Reflex t, MonadHold t m, MonadFix m) => Dynamic t (Maybe a) -> m (Dynamic t (Maybe a))
122+improvingMaybe = scanDynMaybe id (\new _ -> if isJust new then Just new else Nothing)
123+
119124-- | Create a 'Dynamic' that accumulates values from another 'Dynamic'. This
120125-- function does not force its input 'Dynamic' until the output 'Dynamic' is
121126-- forced.