on develop help sign in
Merge pull request #284 from reflex-frp/aa-docs
319fe5fRyan Trinkle
src/Reflex/Class.hs+160−25
@@ -21,9 +21,13 @@
21{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
21{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
22#endif
22#endif
23
23
24+-- |
25+-- Module:
26+-- Reflex.Class
27+-- Description:
24−-- | This module contains the Reflex interface, as well as a variety of
28+-- This module contains the Reflex interface, as well as a variety of
25−-- convenience functions for working with 'Event's, 'Behavior's, and other
29+-- convenience functions for working with 'Event's, 'Behavior's, and other
26−-- signals.
30+-- signals.
27module Reflex.Class
31module Reflex.Class
28 ( module Reflex.Patch
32 ( module Reflex.Patch
29 -- * Primitives
33 -- * Primitives
@@ -256,8 +260,7 @@ class ( MonadHold t (PushM t)
256 -- | Create an 'Event' that will occur whenever the currently-selected input
260 -- | Create an 'Event' that will occur whenever the currently-selected input
257 -- 'Event' occurs
261 -- 'Event' occurs
258 switch :: Behavior t (Event t a) -> Event t a
262 switch :: Behavior t (Event t a) -> Event t a
259− -- | Create an 'Event' that will occur whenever the input event is occurring
263+ -- | Create an 'Event' that will occur whenever the input event is occurring -- and its occurrence value, another 'Event', is also occurring
260− -- and its occurrence value, another 'Event', is also occurring
261 coincidence :: Event t (Event t a) -> Event t a
264 coincidence :: Event t (Event t a) -> Event t a
262 -- | Extract the 'Behavior' of a 'Dynamic'.
265 -- | Extract the 'Behavior' of a 'Dynamic'.
263 current :: Dynamic t a -> Behavior t a
266 current :: Dynamic t a -> Behavior t a
@@ -998,14 +1001,16 @@ distributeListOverDynWith f = fmap (f . map (\(Const2 _ :=> Identity v) -> v) .
998difference :: Reflex t => Event t a -> Event t b -> Event t a
1001difference :: Reflex t => Event t a -> Event t b -> Event t a
999difference = alignEventWithMaybe $ \case
1002difference = alignEventWithMaybe $ \case
1000 This a -> Just a
1003 This a -> Just a
1001− _ -> Nothing
1004+ _ -> Nothing
1002
1005
1006+-- | Zips two values by taking the union of their shapes and combining with the provided function.
1007+-- 'Nothing' values are dropped.
1003alignEventWithMaybe :: Reflex t => (These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
1008alignEventWithMaybe :: Reflex t => (These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
1004−alignEventWithMaybe f ea eb =
1009+alignEventWithMaybe f ea eb = fmapMaybe (f <=< dmapToThese) $
1005− fmapMaybe (f <=< dmapToThese)
1006− $ merge
1007− $ DMap.fromList [LeftTag :=> ea, RightTag :=> eb]
1010+ merge $ DMap.fromList [LeftTag :=> ea, RightTag :=> eb]
1008
1011
1012+-- | Produces an 'Event' that fires only when the input event fires with a 'DSum' key that
1013+-- matches the provided key.
1009filterEventKey
1014filterEventKey
1010 :: forall t m k v a.
1015 :: forall t m k v a.
1011 ( Reflex t
1016 ( Reflex t
@@ -1023,7 +1028,10 @@ filterEventKey k kv' = do
1023 Nothing -> Nothing
1028 Nothing -> Nothing
1024 takeWhileJustE f kv'
1029 takeWhileJustE f kv'
1025
1030
1026−
1031+-- | "Factor" the input 'DSum' 'Event' to produce an 'Event' which
1032+-- fires when the 'DSum' key changes and contains both the value of the
1033+-- 'DSum' at switchover and an 'Event' of values produced by subsequent
1034+-- firings of the input 'Event' that do not change the 'DSum' key.
1027factorEvent
1035factorEvent
1028 :: forall t m k v a.
1036 :: forall t m k v a.
1029 ( Reflex t
1037 ( Reflex t
@@ -1073,26 +1081,94 @@ class Reflex t => Accumulator t f | f -> t where
1073 mapAccumMaybe f = mapAccumMaybeM $ \v o -> return $ f v o
1081 mapAccumMaybe f = mapAccumMaybeM $ \v o -> return $ f v o
1074 mapAccumMaybeM :: (MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (f a, Event t c)
1082 mapAccumMaybeM :: (MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (f a, Event t c)
1075
1083
1084+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1085+-- with the provided function. See 'foldDyn'.
1086+accumDyn
1076−accumDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> a) -> a -> Event t b -> m (Dynamic t a)
1087+ :: (Reflex t, MonadHold t m, MonadFix m)
1088+ => (a -> b -> a)
1089+ -> a
1090+ -> Event t b
1091+ -> m (Dynamic t a)
1077accumDyn f = accumMaybeDyn $ \v o -> Just $ f v o
1092accumDyn f = accumMaybeDyn $ \v o -> Just $ f v o
1093+
1094+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1095+-- with the provided 'PushM' action.
1096+accumMDyn
1078−accumMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t a) -> a -> Event t b -> m (Dynamic t a)
1097+ :: (Reflex t, MonadHold t m, MonadFix m)
1098+ => (a -> b -> PushM t a)
1099+ -> a
1100+ -> Event t b
1101+ -> m (Dynamic t a)
1079accumMDyn f = accumMaybeMDyn $ \v o -> Just <$> f v o
1102accumMDyn f = accumMaybeMDyn $ \v o -> Just <$> f v o
1103+
1104+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1105+-- with the provided function, discarding 'Nothing' results.
1106+accumMaybeDyn
1080−accumMaybeDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe a) -> a -> Event t b -> m (Dynamic t a)
1107+ :: (Reflex t, MonadHold t m, MonadFix m)
1108+ => (a -> b -> Maybe a)
1109+ -> a
1110+ -> Event t b
1111+ -> m (Dynamic t a)
1081accumMaybeDyn f = accumMaybeMDyn $ \v o -> return $ f v o
1112accumMaybeDyn f = accumMaybeMDyn $ \v o -> return $ f v o
1113+
1114+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1115+-- with the provided 'PushM' action, discarding 'Nothing' results.
1116+accumMaybeMDyn
1082−accumMaybeMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Dynamic t a)
1117+ :: (Reflex t, MonadHold t m, MonadFix m)
1118+ => (a -> b -> PushM t (Maybe a))
1119+ -> a
1120+ -> Event t b
1121+ -> m (Dynamic t a)
1083accumMaybeMDyn f z e = do
1122accumMaybeMDyn f z e = do
1084 rec let e' = flip push e $ \o -> do
1123 rec let e' = flip push e $ \o -> do
1085 v <- sample $ current d'
1124 v <- sample $ current d'
1086 f v o
1125 f v o
1087 d' <- holdDyn z e'
1126 d' <- holdDyn z e'
1088 return d'
1127 return d'
1128+
1129+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event'
1130+-- with a function that both accumulates and produces a value to fire
1131+-- as an 'Event'. Returns both the accumulated value and an 'Event'.
1132+mapAccumDyn
1089−mapAccumDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1133+ :: (Reflex t, MonadHold t m, MonadFix m)
1134+ => (a -> b -> (a, c))
1135+ -> a
1136+ -> Event t b
1137+ -> m (Dynamic t a, Event t c)
1090mapAccumDyn f = mapAccumMaybeDyn $ \v o -> bimap Just Just $ f v o
1138mapAccumDyn f = mapAccumMaybeDyn $ \v o -> bimap Just Just $ f v o
1139+
1140+-- | Similar to 'mapAccumDyn' except that the combining function is a
1141+-- 'PushM' action.
1142+mapAccumMDyn
1091−mapAccumMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1143+ :: (Reflex t, MonadHold t m, MonadFix m)
1144+ => (a -> b -> PushM t (a, c))
1145+ -> a
1146+ -> Event t b
1147+ -> m (Dynamic t a, Event t c)
1092mapAccumMDyn f = mapAccumMaybeMDyn $ \v o -> bimap Just Just <$> f v o
1148mapAccumMDyn f = mapAccumMaybeMDyn $ \v o -> bimap Just Just <$> f v o
1149+
1150+-- | Accumulate a 'Dynamic' by folding occurrences of an 'Event' with
1151+-- a function that both optionally accumulates and optionally produces
1152+-- a value to fire as a separate output 'Event'.
1153+-- Note that because 'Nothing's are discarded in both cases, the output
1154+-- 'Event' may fire even though the output 'Dynamic' has not changed, and
1155+-- the output 'Dynamic' may update even when the output 'Event' is not firing.
1156+mapAccumMaybeDyn
1093−mapAccumMaybeDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1157+ :: (Reflex t, MonadHold t m, MonadFix m)
1158+ => (a -> b -> (Maybe a, Maybe c))
1159+ -> a
1160+ -> Event t b
1161+ -> m (Dynamic t a, Event t c)
1094mapAccumMaybeDyn f = mapAccumMaybeMDyn $ \v o -> return $ f v o
1162mapAccumMaybeDyn f = mapAccumMaybeMDyn $ \v o -> return $ f v o
1163+
1164+-- | Like 'mapAccumMaybeDyn' except that the combining function is a
1165+-- 'PushM' action.
1166+mapAccumMaybeMDyn
1095−mapAccumMaybeMDyn :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Dynamic t a, Event t c)
1167+ :: (Reflex t, MonadHold t m, MonadFix m)
1168+ => (a -> b -> PushM t (Maybe a, Maybe c))
1169+ -> a
1170+ -> Event t b
1171+ -> m (Dynamic t a, Event t c)
1096mapAccumMaybeMDyn f z e = do
1172mapAccumMaybeMDyn f z e = do
1097 rec let e' = flip push e $ \o -> do
1173 rec let e' = flip push e $ \o -> do
1098 v <- sample $ current d'
1174 v <- sample $ current d'
@@ -1103,15 +1179,39 @@ mapAccumMaybeMDyn f z e = do
1103 d' <- holdDyn z $ fmapMaybe fst e'
1179 d' <- holdDyn z $ fmapMaybe fst e'
1104 return (d', fmapMaybe snd e')
1180 return (d', fmapMaybe snd e')
1105
1181
1182+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
1183+-- with the provided function.
1106{-# INLINE accumB #-}
1184{-# INLINE accumB #-}
1185+accumB
1107−accumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> a) -> a -> Event t b -> m (Behavior t a)
1186+ :: (Reflex t, MonadHold t m, MonadFix m)
1187+ => (a -> b -> a)
1188+ -> a
1189+ -> Event t b
1190+ -> m (Behavior t a)
1108accumB f = accumMaybeB $ \v o -> Just $ f v o
1191accumB f = accumMaybeB $ \v o -> Just $ f v o
1192+
1193+-- | Like 'accumB' except that the combining function is a 'PushM' action.
1109{-# INLINE accumMB #-}
1194{-# INLINE accumMB #-}
1195+accumMB
1110−accumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t a) -> a -> Event t b -> m (Behavior t a)
1196+ :: (Reflex t, MonadHold t m, MonadFix m)
1197+ => (a -> b -> PushM t a)
1198+ -> a
1199+ -> Event t b
1200+ -> m (Behavior t a)
1111accumMB f = accumMaybeMB $ \v o -> Just <$> f v o
1201accumMB f = accumMaybeMB $ \v o -> Just <$> f v o
1202+
1203+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
1204+-- with the provided function, discarding 'Nothing' results.
1112{-# INLINE accumMaybeB #-}
1205{-# INLINE accumMaybeB #-}
1206+accumMaybeB
1113−accumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> Maybe a) -> a -> Event t b -> m (Behavior t a)
1207+ :: (Reflex t, MonadHold t m, MonadFix m)
1208+ => (a -> b -> Maybe a)
1209+ -> a
1210+ -> Event t b
1211+ -> m (Behavior t a)
1114accumMaybeB f = accumMaybeMB $ \v o -> return $ f v o
1212accumMaybeB f = accumMaybeMB $ \v o -> return $ f v o
1213+
1214+-- | Like 'accumMaybeB' except that the combining function is a 'PushM' action.
1115{-# INLINE accumMaybeMB #-}
1215{-# INLINE accumMaybeMB #-}
1116accumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
1216accumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a)) -> a -> Event t b -> m (Behavior t a)
1117accumMaybeMB f z e = do
1217accumMaybeMB f z e = do
@@ -1120,16 +1220,42 @@ accumMaybeMB f z e = do
1120 f v o
1220 f v o
1121 d' <- hold z e'
1221 d' <- hold z e'
1122 return d'
1222 return d'
1223+
1224+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
1225+-- with a function that both accumulates and produces a value to fire
1226+-- as an 'Event'. Returns both the accumulated value and an 'Event'.
1123{-# INLINE mapAccumB #-}
1227{-# INLINE mapAccumB #-}
1228+mapAccumB
1124−mapAccumB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1229+ :: (Reflex t, MonadHold t m, MonadFix m)
1230+ => (a -> b -> (a, c))
1231+ -> a
1232+ -> Event t b
1233+ -> m (Behavior t a, Event t c)
1125mapAccumB f = mapAccumMaybeB $ \v o -> bimap Just Just $ f v o
1234mapAccumB f = mapAccumMaybeB $ \v o -> bimap Just Just $ f v o
1235+
1236+-- | Like 'mapAccumB' except that the combining function is a 'PushM' action.
1126{-# INLINE mapAccumMB #-}
1237{-# INLINE mapAccumMB #-}
1238+mapAccumMB
1127−mapAccumMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (a, c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1239+ :: (Reflex t, MonadHold t m, MonadFix m)
1240+ => (a -> b -> PushM t (a, c))
1241+ -> a
1242+ -> Event t b
1243+ -> m (Behavior t a, Event t c)
1128mapAccumMB f = mapAccumMaybeMB $ \v o -> bimap Just Just <$> f v o
1244mapAccumMB f = mapAccumMaybeMB $ \v o -> bimap Just Just <$> f v o
1245+
1246+-- | Accumulate a 'Behavior' by folding occurrences of an 'Event' with
1247+-- a function that both optionally accumulates and optionally produces
1248+-- a value to fire as a separate output 'Event'. 'Nothing's are discarded.
1129{-# INLINE mapAccumMaybeB #-}
1249{-# INLINE mapAccumMaybeB #-}
1250+mapAccumMaybeB
1130−mapAccumMaybeB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1251+ :: (Reflex t, MonadHold t m, MonadFix m)
1252+ => (a -> b -> (Maybe a, Maybe c))
1253+ -> a
1254+ -> Event t b
1255+ -> m (Behavior t a, Event t c)
1131mapAccumMaybeB f = mapAccumMaybeMB $ \v o -> return $ f v o
1256mapAccumMaybeB f = mapAccumMaybeMB $ \v o -> return $ f v o
1132
1257
1258+-- | LIke 'mapAccumMaybeB' except that the combining function is a 'PushM' action.
1133{-# INLINE mapAccumMaybeMB #-}
1259{-# INLINE mapAccumMaybeMB #-}
1134mapAccumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1260mapAccumMaybeMB :: (Reflex t, MonadHold t m, MonadFix m) => (a -> b -> PushM t (Maybe a, Maybe c)) -> a -> Event t b -> m (Behavior t a, Event t c)
1135mapAccumMaybeMB f z e = do
1261mapAccumMaybeMB f z e = do
@@ -1284,38 +1410,47 @@ infixl 4 <@
1284-- Cheap Functions
1410-- Cheap Functions
1285------------------
1411------------------
1286
1412
1413+-- | A "cheap" version of 'pushAlways'. See the performance note on 'pushCheap'.
1287{-# INLINE pushAlwaysCheap #-}
1414{-# INLINE pushAlwaysCheap #-}
1288pushAlwaysCheap :: Reflex t => (a -> PushM t b) -> Event t a -> Event t b
1415pushAlwaysCheap :: Reflex t => (a -> PushM t b) -> Event t a -> Event t b
1289pushAlwaysCheap f = pushCheap (fmap Just . f)
1416pushAlwaysCheap f = pushCheap (fmap Just . f)
1290
1417
1418+-- | A "cheap" version of 'fmapMaybe'. See the performance note on 'pushCheap'.
1291{-# INLINE fmapMaybeCheap #-}
1419{-# INLINE fmapMaybeCheap #-}
1292fmapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
1420fmapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
1293fmapMaybeCheap f = pushCheap $ return . f
1421fmapMaybeCheap f = pushCheap $ return . f
1294
1422
1423+-- | A "cheap" version of 'fforMaybe'. See the performance note on 'pushCheap'.
1295{-# INLINE fforMaybeCheap #-}
1424{-# INLINE fforMaybeCheap #-}
1296fforMaybeCheap :: Reflex t => Event t a -> (a -> Maybe b) -> Event t b
1425fforMaybeCheap :: Reflex t => Event t a -> (a -> Maybe b) -> Event t b
1297fforMaybeCheap = flip fmapMaybeCheap
1426fforMaybeCheap = flip fmapMaybeCheap
1298
1427
1428+-- | A "cheap" version of 'ffor'. See the performance note on 'pushCheap'.
1299{-# INLINE fforCheap #-}
1429{-# INLINE fforCheap #-}
1300fforCheap :: Reflex t => Event t a -> (a -> b) -> Event t b
1430fforCheap :: Reflex t => Event t a -> (a -> b) -> Event t b
1301fforCheap = flip fmapCheap
1431fforCheap = flip fmapCheap
1302
1432
1433+-- | A "cheap" version of 'fmap'. See the performance note on 'pushCheap'.
1303{-# INLINE fmapCheap #-}
1434{-# INLINE fmapCheap #-}
1304fmapCheap :: Reflex t => (a -> b) -> Event t a -> Event t b
1435fmapCheap :: Reflex t => (a -> b) -> Event t a -> Event t b
1305fmapCheap f = pushCheap $ return . Just . f
1436fmapCheap f = pushCheap $ return . Just . f
1306
1437
1438+-- | A "cheap" version of 'tag'. See the performance note on 'pushCheap'.
1307{-# INLINE tagCheap #-}
1439{-# INLINE tagCheap #-}
1308tagCheap :: Reflex t => Behavior t b -> Event t a -> Event t b
1440tagCheap :: Reflex t => Behavior t b -> Event t a -> Event t b
1309tagCheap b = pushAlwaysCheap $ \_ -> sample b
1441tagCheap b = pushAlwaysCheap $ \_ -> sample b
1310
1442
1443+-- | A "cheap" version of 'mergeWithCheap'. See the performance note on 'pushCheap'.
1311{-# INLINE mergeWithCheap #-}
1444{-# INLINE mergeWithCheap #-}
1312mergeWithCheap :: Reflex t => (a -> a -> a) -> [Event t a] -> Event t a
1445mergeWithCheap :: Reflex t => (a -> a -> a) -> [Event t a] -> Event t a
1313mergeWithCheap = mergeWithCheap' id
1446mergeWithCheap = mergeWithCheap' id
1314
1447
1448+-- | A "cheap" version of 'mergeWithCheap''. See the performance note on 'pushCheap'.
1315{-# INLINE mergeWithCheap' #-}
1449{-# INLINE mergeWithCheap' #-}
1316mergeWithCheap' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
1450mergeWithCheap' :: Reflex t => (a -> b) -> (b -> b -> b) -> [Event t a] -> Event t b
1317mergeWithCheap' f g = mergeWithFoldCheap' $ foldl1 g . fmap f
1451mergeWithCheap' f g = mergeWithFoldCheap' $ foldl1 g . fmap f
1318
1452
1453+-- | A "cheap" version of 'mergeWithFoldCheap''. See the performance note on 'pushCheap'.
1319{-# INLINE mergeWithFoldCheap' #-}
1454{-# INLINE mergeWithFoldCheap' #-}
1320mergeWithFoldCheap' :: Reflex t => (NonEmpty a -> b) -> [Event t a] -> Event t b
1455mergeWithFoldCheap' :: Reflex t => (NonEmpty a -> b) -> [Event t a] -> Event t b
1321mergeWithFoldCheap' f es =
1456mergeWithFoldCheap' f es =
src/Reflex/Collection.hs+8
@@ -10,6 +10,9 @@
10#ifdef USE_REFLEX_OPTIMIZER
10#ifdef USE_REFLEX_OPTIMIZER
11{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
11{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
12#endif
12#endif
13+-- |
14+-- Module:
15+-- Reflex.Collection
13module Reflex.Collection
16module Reflex.Collection
14 (
17 (
15 -- * Widgets on Collections
18 -- * Widgets on Collections
@@ -38,6 +41,9 @@ import Reflex.Adjustable.Class
38import Reflex.Dynamic
41import Reflex.Dynamic
39import Reflex.PostBuild.Class
42import Reflex.PostBuild.Class
40
43
44+-- | Create a set of widgets based on the provided 'Map'. When the
45+-- input 'Event' fires, remove widgets for keys with the value 'Nothing'
46+-- and add/replace widgets for keys with 'Just' values.
41listHoldWithKey
47listHoldWithKey
42 :: forall t m k v a
48 :: forall t m k v a
43 . (Ord k, Adjustable t m, MonadHold t m)
49 . (Ord k, Adjustable t m, MonadHold t m)
@@ -182,6 +188,8 @@ selectViewListWithKey selection vals mkChild = do
182 return $ fmap ((,) k) selectSelf
188 return $ fmap ((,) k) selectSelf
183 return $ switchPromptlyDyn $ leftmost . Map.elems <$> selectChild
189 return $ switchPromptlyDyn $ leftmost . Map.elems <$> selectChild
184
190
191+-- | Like 'selectViewListWithKey' but discards the value of the list
192+-- item widget's output 'Event'.
185selectViewListWithKey_
193selectViewListWithKey_
186 :: forall t m k v a
194 :: forall t m k v a
187 . (Adjustable t m, Ord k, PostBuild t m, MonadHold t m, MonadFix m)
195 . (Adjustable t m, Ord k, PostBuild t m, MonadHold t m, MonadFix m)
src/Reflex/Dynamic.hs+6−2
@@ -17,8 +17,12 @@
17#ifdef USE_REFLEX_OPTIMIZER
17#ifdef USE_REFLEX_OPTIMIZER
18{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
18{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
19#endif
19#endif
20+-- |
21+-- Module:
22+-- Reflex.Dynamic
23+-- Description:
20−-- | This module contains various functions for working with 'Dynamic' values.
24+-- This module contains various functions for working with 'Dynamic' values.
21−-- 'Dynamic' and its primitives have been moved to the 'Reflex' class.
25+-- 'Dynamic' and its primitives have been moved to the 'Reflex' class.
22module Reflex.Dynamic
26module Reflex.Dynamic
23 ( -- * Basics
27 ( -- * Basics
24 Dynamic -- Abstract so we can preserve the law that the current value is always equal to the most recent update
28 Dynamic -- Abstract so we can preserve the law that the current value is always equal to the most recent update
src/Reflex/FastWeak.hs+10−6
@@ -6,14 +6,18 @@
6{-# LANGUAGE JavaScriptFFI #-}
6{-# LANGUAGE JavaScriptFFI #-}
7#endif
7#endif
8
8
9+-- |
10+-- Module:
11+-- Reflex.FastWeak
12+-- Description:
9−-- | 'FastWeak' is a weak pointer to some value, and 'FastWeakTicket' ensures the value
13+-- 'FastWeak' is a weak pointer to some value, and 'FastWeakTicket' ensures the value
10−-- referred to by a 'FastWeak' stays live while the ticket is held (live).
14+-- referred to by a 'FastWeak' stays live while the ticket is held (live).
11--
15--
12−-- On GHC or GHCJS when not built with the @fast-weak@ cabal flag, 'FastWeak' is a wrapper
16+-- On GHC or GHCJS when not built with the @fast-weak@ cabal flag, 'FastWeak' is a wrapper
13−-- around the simple version of 'System.Mem.Weak.Weak' where the key and value are the same.
17+-- around the simple version of 'System.Mem.Weak.Weak' where the key and value are the same.
14--
18--
15−-- On GHCJS when built with the @fast-weak@ cabal flag, 'FastWeak' is implemented directly
19+-- On GHCJS when built with the @fast-weak@ cabal flag, 'FastWeak' is implemented directly
16−-- in JS using @h$FastWeak@ and @h$FastWeakTicket@ which are a nonstandard part of the GHCJS RTS.
20+-- in JS using @h$FastWeak@ and @h$FastWeakTicket@ which are a nonstandard part of the GHCJS RTS.
17module Reflex.FastWeak
21module Reflex.FastWeak
18 ( FastWeakTicket
22 ( FastWeakTicket
19 , FastWeak
23 , FastWeak
src/Reflex/FunctorMaybe.hs+6−2
@@ -2,8 +2,12 @@
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE StandaloneDeriving #-}
3{-# LANGUAGE StandaloneDeriving #-}
4
4
5+-- |
6+-- Module:
7+-- Reflex.FunctorMaybe
8+-- Description:
5−-- | This module defines the FunctorMaybe class, which extends Functors with the
9+-- This module defines the FunctorMaybe class, which extends Functors with the
6−-- ability to delete values.
10+-- ability to delete values.
7module Reflex.FunctorMaybe
11module Reflex.FunctorMaybe
8 ( FunctorMaybe (..)
12 ( FunctorMaybe (..)
9 ) where
13 ) where
src/Reflex/Network.hs+10−4
@@ -3,6 +3,11 @@
3#ifdef USE_REFLEX_OPTIMIZER
3#ifdef USE_REFLEX_OPTIMIZER
4{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
4{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
5#endif
5#endif
6+-- |
7+-- Module:
8+-- Reflex.Network
9+-- Description:
10+-- This module provides combinators for building FRP graphs/networks and modifying them dynamically.
6module Reflex.Network
11module Reflex.Network
7 ( networkView
12 ( networkView
8 , networkHold
13 , networkHold
@@ -14,16 +19,17 @@ import Reflex.Adjustable.Class
14import Reflex.NotReady.Class
19import Reflex.NotReady.Class
15import Reflex.PostBuild.Class
20import Reflex.PostBuild.Class
16
21
17−-- | Given a Dynamic of network-creating actions, create a network that is recreated whenever the Dynamic updates.
22+-- | A 'Dynamic' "network": Takes a 'Dynamic' of network-creating actions and replaces the network whenever the 'Dynamic' updates.
18−-- The returned Event of network results occurs when the Dynamic does.
23+-- The returned Event of network results fires when the 'Dynamic' updates.
19−-- Note: Often, the type 'a' is an Event, in which case the return value is an Event-of-Events that would typically be flattened (via 'switchPromptly').
24+-- Note: Often, the type 'a' is an Event, in which case the return value is an Event-of-Events, where the outer 'Event' fires
25+-- when switching networks. Such an 'Event' would typically be flattened (via 'switchPromptly').
20networkView :: (NotReady t m, Adjustable t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
26networkView :: (NotReady t m, Adjustable t m, PostBuild t m) => Dynamic t (m a) -> m (Event t a)
21networkView child = do
27networkView child = do
22 postBuild <- getPostBuild
28 postBuild <- getPostBuild
23 let newChild = leftmost [updated child, tagCheap (current child) postBuild]
29 let newChild = leftmost [updated child, tagCheap (current child) postBuild]
24 snd <$> runWithReplace notReady newChild
30 snd <$> runWithReplace notReady newChild
25
31
26−-- | Given an initial network and an Event of network-creating actions, create a network that is recreated whenever the Event fires.
32+-- | Given an initial "network" and an 'Event' of network-creating actions, create a network that is recreated whenever the Event fires.
27-- The returned Dynamic of network results occurs when the Event does.
33-- The returned Dynamic of network results occurs when the Event does.
28-- Note: Often, the type 'a' is an Event, in which case the return value is a Dynamic-of-Events that would typically be flattened.
34-- Note: Often, the type 'a' is an Event, in which case the return value is a Dynamic-of-Events that would typically be flattened.
29networkHold :: (Adjustable t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
35networkHold :: (Adjustable t m, MonadHold t m) => m a -> Event t (m a) -> m (Dynamic t a)
src/Reflex/Optimizer.hs+8−4
@@ -1,10 +1,14 @@
1−-- | This module provides a GHC plugin designed to improve code that uses
2−-- Reflex. Currently, it just adds an INLINABLE pragma to any top-level
3−-- definition that doesn't have an explicit inlining pragma. In the future,
4−-- additional optimizations are likely to be added.
5{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
6{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE LambdaCase #-}
7{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4+-- |
5+-- Module:
6+-- Reflex.Optimizer
7+-- Description:
8+-- This module provides a GHC plugin designed to improve code that uses
9+-- Reflex. Currently, it just adds an INLINABLE pragma to any top-level
10+-- definition that doesn't have an explicit inlining pragma. In the future,
11+-- additional optimizations are likely to be added.
8module Reflex.Optimizer
12module Reflex.Optimizer
9 ( plugin
13 ( plugin
10 ) where
14 ) where
src/Reflex/Patch.hs+6−5
@@ -1,6 +1,10 @@
1−-- | This module defines the 'Patch' class, which is used by Reflex to manage
2−-- changes to 'Reflex.Class.Incremental' values.
3{-# LANGUAGE TypeFamilies #-}
1{-# LANGUAGE TypeFamilies #-}
2+-- |
3+-- Module:
4+-- Reflex.Patch
5+-- Description:
6+-- This module defines the 'Patch' class, which is used by Reflex to manage
7+-- changes to 'Reflex.Class.Incremental' values.
4module Reflex.Patch
8module Reflex.Patch
5 ( module Reflex.Patch
9 ( module Reflex.Patch
6 , module X
10 , module X
@@ -17,11 +21,8 @@ import Reflex.Patch.Map as X
17import Reflex.Patch.MapWithMove as X (PatchMapWithMove, patchMapWithMoveNewElements,
21import Reflex.Patch.MapWithMove as X (PatchMapWithMove, patchMapWithMoveNewElements,
18 patchMapWithMoveNewElementsMap, unPatchMapWithMove,
22 patchMapWithMoveNewElementsMap, unPatchMapWithMove,
19 unsafePatchMapWithMove)
23 unsafePatchMapWithMove)
20−
21import Data.Semigroup (Semigroup (..), (<>))
24import Data.Semigroup (Semigroup (..), (<>))
22
25
23−---- Patches based on commutative groups
24−
25-- | A 'Group' is a 'Monoid' where every element has an inverse.
26-- | A 'Group' is a 'Monoid' where every element has an inverse.
26class (Semigroup q, Monoid q) => Group q where
27class (Semigroup q, Monoid q) => Group q where
27 negateG :: q -> q
28 negateG :: q -> q
src/Reflex/Profiled.hs+6
@@ -8,6 +8,12 @@
8{-# LANGUAGE StandaloneDeriving #-}
8{-# LANGUAGE StandaloneDeriving #-}
9{-# LANGUAGE TypeFamilies #-}
9{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE UndecidableInstances #-}
10{-# LANGUAGE UndecidableInstances #-}
11+-- |
12+-- Module:
13+-- Reflex.Profiled
14+-- Description:
15+-- This module contains an instance of the 'Reflex' class that provides
16+-- profiling/cost-center information.
11module Reflex.Profiled where
17module Reflex.Profiled where
12
18
13import Control.Lens hiding (children)
19import Control.Lens hiding (children)
src/Reflex/Pure.hs+7−5
@@ -13,11 +13,13 @@
13-- * MonadSample (Pure t) ((->) t)
13-- * MonadSample (Pure t) ((->) t)
14-- * MonadHold (Pure t) ((->) t)
14-- * MonadHold (Pure t) ((->) t)
15{-# OPTIONS_GHC -fno-warn-orphans #-}
15{-# OPTIONS_GHC -fno-warn-orphans #-}
16−
16+-- |
17+-- Module: Reflex.Pure
18+-- Description:
17−-- | This module provides a pure implementation of Reflex, which is intended to
19+-- This module provides a pure implementation of Reflex, which is intended to
18−-- serve as a reference for the semantics of the Reflex class. All
20+-- serve as a reference for the semantics of the Reflex class. All
19−-- implementations of Reflex should produce the same results as this
21+-- implementations of Reflex should produce the same results as this
20−-- implementation, although performance and laziness/strictness may differ.
22+-- implementation, although performance and laziness/strictness may differ.
21module Reflex.Pure
23module Reflex.Pure
22 ( Pure
24 ( Pure
23 , Behavior (..)
25 , Behavior (..)
src/Reflex/Spider.hs+5−2
@@ -1,6 +1,9 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2+-- |
3+-- Module:
4+-- Reflex.Spider
5+-- Description:
2−-- | This module exports all of the user-facing functionality of the 'Spider'
6+-- This module exports all of the user-facing functionality of the 'Spider' 'Reflex' engine
3−-- 'Reflex' engine
4module Reflex.Spider
7module Reflex.Spider
5 ( Spider
8 ( Spider
6 , SpiderTimeline
9 , SpiderTimeline
src/Reflex/Time.hs+23−13
@@ -11,6 +11,11 @@
11#ifdef USE_TEMPLATE_HASKELL
11#ifdef USE_TEMPLATE_HASKELL
12{-# LANGUAGE TemplateHaskell #-}
12{-# LANGUAGE TemplateHaskell #-}
13#endif
13#endif
14+-- |
15+-- Module:
16+-- Reflex.Time
17+-- Description:
18+-- Clocks, timers, and other time-related functions.
14module Reflex.Time where
19module Reflex.Time where
15
20
16import Reflex.Class
21import Reflex.Class
@@ -37,38 +42,39 @@ import Data.Typeable
37import GHC.Generics (Generic)
42import GHC.Generics (Generic)
38import System.Random
43import System.Random
39
44
45+-- | Metadata associated with a timer "tick"
40data TickInfo
46data TickInfo
41 = TickInfo { _tickInfo_lastUTC :: UTCTime
47 = TickInfo { _tickInfo_lastUTC :: UTCTime
42 -- ^ UTC time immediately after the last tick.
48 -- ^ UTC time immediately after the last tick.
43 , _tickInfo_n :: Integer
49 , _tickInfo_n :: Integer
44− -- ^ Number of time periods since t0
50+ -- ^ Number of time periods or ticks since the start of the timer
45 , _tickInfo_alreadyElapsed :: NominalDiffTime
51 , _tickInfo_alreadyElapsed :: NominalDiffTime
46− -- ^ Amount of time already elapsed in the current tick period.
52+ -- ^ Amount of time that has elapsed in the current tick period.
47 }
53 }
48 deriving (Eq, Ord, Show, Typeable)
54 deriving (Eq, Ord, Show, Typeable)
49
55
56+-- | Fires an 'Event' once every time provided interval elapses, approximately.
57+-- The provided 'UTCTime' is used bootstrap the determination of how much time has elapsed with each tick.
50−-- | Special case of 'tickLossyFrom' that uses the post-build event to start the
58+-- This is a special case of 'tickLossyFrom' that uses the post-build event to start the tick thread.
51−-- tick thread.
52tickLossy :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> UTCTime -> m (Event t TickInfo)
59tickLossy :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> UTCTime -> m (Event t TickInfo)
53tickLossy dt t0 = tickLossyFrom dt t0 =<< getPostBuild
60tickLossy dt t0 = tickLossyFrom dt t0 =<< getPostBuild
54
61
55−-- | Special case of 'tickLossyFrom' that uses the post-build event to start the
62+-- | Fires an 'Event' once every time provided interval elapses, approximately.
56−-- tick thread and the time of the post-build as the tick basis time.
63+-- This is a special case of 'tickLossyFrom' that uses the post-build event to start the tick thread and the time of the post-build as the tick basis time.
57tickLossyFromPostBuildTime :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> m (Event t TickInfo)
64tickLossyFromPostBuildTime :: (PostBuild t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m) => NominalDiffTime -> m (Event t TickInfo)
58tickLossyFromPostBuildTime dt = do
65tickLossyFromPostBuildTime dt = do
59 postBuild <- getPostBuild
66 postBuild <- getPostBuild
60 postBuildTime <- performEvent $ liftIO getCurrentTime <$ postBuild
67 postBuildTime <- performEvent $ liftIO getCurrentTime <$ postBuild
61 tickLossyFrom' $ (dt,) <$> postBuildTime
68 tickLossyFrom' $ (dt,) <$> postBuildTime
62
69
63−-- | Send events over time with the given basis time and interval
64−-- If the system starts running behind, occurrences will be dropped rather than buffered
70+-- | Fires an 'Event' approximately each time the provided interval elapses. If the system starts running behind, occurrences will be dropped rather than buffered.
65−-- Each occurrence of the resulting event will contain the index of the current interval, with 0 representing the basis time
71+-- Each occurrence of the resulting event will contain the index of the current interval, with 0 representing the provided initial time.
66tickLossyFrom
72tickLossyFrom
67 :: (PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m)
73 :: (PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m)
68 => NominalDiffTime
74 => NominalDiffTime
69 -- ^ The length of a tick interval
75 -- ^ The length of a tick interval
70 -> UTCTime
76 -> UTCTime
71− -- ^ The basis time from which intervals count
77+ -- ^ The basis time from which intervals count and with which the initial calculation of elapsed time will be made.
72 -> Event t a
78 -> Event t a
73 -- ^ Event that starts a tick generation thread. Usually you want this to
79 -- ^ Event that starts a tick generation thread. Usually you want this to
74 -- be something like the result of getPostBuild that only fires once. But
80 -- be something like the result of getPostBuild that only fires once. But
@@ -76,12 +82,12 @@ tickLossyFrom
76 -> m (Event t TickInfo)
82 -> m (Event t TickInfo)
77tickLossyFrom dt t0 e = tickLossyFrom' $ (dt, t0) <$ e
83tickLossyFrom dt t0 e = tickLossyFrom' $ (dt, t0) <$ e
78
84
79−-- | Generalization of tickLossyFrom that takes dt and t0 in the event.
85+-- | Generalization of tickLossyFrom that takes the delay and initial time as an 'Event'.
80tickLossyFrom'
86tickLossyFrom'
81 :: (PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m)
87 :: (PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), MonadFix m)
82 => Event t (NominalDiffTime, UTCTime)
88 => Event t (NominalDiffTime, UTCTime)
83 -- ^ Event that starts a tick generation thread. Usually you want this to
89 -- ^ Event that starts a tick generation thread. Usually you want this to
84− -- be something like the result of getPostBuild that only fires once. But
90+ -- be something like the result of 'getPostBuild' that only fires once. But
85 -- there could be uses for starting multiple timer threads.
91 -- there could be uses for starting multiple timer threads.
86 -> m (Event t TickInfo)
92 -> m (Event t TickInfo)
87tickLossyFrom' e = do
93tickLossyFrom' e = do
@@ -92,12 +98,16 @@ tickLossyFrom' e = do
92 Concurrent.delay $ ceiling $ (fst pair - _tickInfo_alreadyElapsed tick) * 1000000
98 Concurrent.delay $ ceiling $ (fst pair - _tickInfo_alreadyElapsed tick) * 1000000
93 cb (tick, pair)
99 cb (tick, pair)
94
100
101+-- | Like 'tickLossy', but immediately calculates the first tick and provides a 'Dynamic' that is updated as ticks fire.
95clockLossy :: (MonadIO m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), PostBuild t m, MonadHold t m, MonadFix m) => NominalDiffTime -> UTCTime -> m (Dynamic t TickInfo)
102clockLossy :: (MonadIO m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m), PostBuild t m, MonadHold t m, MonadFix m) => NominalDiffTime -> UTCTime -> m (Dynamic t TickInfo)
96clockLossy dt t0 = do
103clockLossy dt t0 = do
97 initial <- liftIO $ getCurrentTick dt t0
104 initial <- liftIO $ getCurrentTick dt t0
98 e <- tickLossy dt t0
105 e <- tickLossy dt t0
99 holdDyn initial e
106 holdDyn initial e
100
107
108+-- | Generates a 'TickInfo', given the specified interval and timestamp. The 'TickInfo' will include the
109+-- current time, the number of ticks that have elapsed since the timestamp, and the amount of time that
110+-- has elapsed since the start time of this tick.
101getCurrentTick :: NominalDiffTime -> UTCTime -> IO TickInfo
111getCurrentTick :: NominalDiffTime -> UTCTime -> IO TickInfo
102getCurrentTick dt t0 = do
112getCurrentTick dt t0 = do
103 t <- getCurrentTime
113 t <- getCurrentTime
@@ -278,7 +288,7 @@ data ThrottleState b
278
288
279data ThrottleBuffer b
289data ThrottleBuffer b
280 = ThrottleBuffer_Empty -- Empty conflicts with lens, and hiding it would require turning
290 = ThrottleBuffer_Empty -- Empty conflicts with lens, and hiding it would require turning
281− -- on PatternSynonyms
291+ -- on PatternSynonyms
282 | ThrottleBuffer_Full b
292 | ThrottleBuffer_Full b
283 deriving (Eq, Ord, Show, Functor, Foldable, Traversable, Generic, Data, Typeable)
293 deriving (Eq, Ord, Show, Functor, Foldable, Traversable, Generic, Data, Typeable)
284
294
src/Reflex/Workflow.hs+13−1
@@ -1,7 +1,13 @@
1{-# LANGUAGE RecursiveDo #-}
1{-# LANGUAGE RecursiveDo #-}
2{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3+-- |
4+-- Module:
5+-- Reflex.Workflow
6+-- Description:
7+-- Provides a convenient way to describe a series of interrelated widgets that
8+-- can send data to, invoke, and replace one another. Useful for modeling user interface
9+-- "workflows."
3module Reflex.Workflow (
10module Reflex.Workflow (
4− -- * Workflows
5 Workflow (..)
11 Workflow (..)
6 , workflow
12 , workflow
7 , workflowView
13 , workflowView
@@ -18,21 +24,27 @@ import Reflex.Network
18import Reflex.NotReady.Class
24import Reflex.NotReady.Class
19import Reflex.PostBuild.Class
25import Reflex.PostBuild.Class
20
26
27+-- | A widget in a workflow
28+-- When the 'Event' returned by a 'Workflow' fires, the current 'Workflow' is replaced by the one inside the firing 'Event'. A series of 'Workflow's must share the same return type.
21newtype Workflow t m a = Workflow { unWorkflow :: m (a, Event t (Workflow t m a)) }
29newtype Workflow t m a = Workflow { unWorkflow :: m (a, Event t (Workflow t m a)) }
22
30
31+-- | Runs a 'Workflow' and returns the 'Dynamic' result of the 'Workflow' (i.e., a 'Dynamic' of the value produced by the current 'Workflow' node, and whose update 'Event' fires whenever one 'Workflow' is replaced by another).
23workflow :: forall t m a. (Reflex t, Adjustable t m, MonadFix m, MonadHold t m) => Workflow t m a -> m (Dynamic t a)
32workflow :: forall t m a. (Reflex t, Adjustable t m, MonadFix m, MonadHold t m) => Workflow t m a -> m (Dynamic t a)
24workflow w0 = do
33workflow w0 = do
25 rec eResult <- networkHold (unWorkflow w0) $ fmap unWorkflow $ switch $ snd <$> current eResult
34 rec eResult <- networkHold (unWorkflow w0) $ fmap unWorkflow $ switch $ snd <$> current eResult
26 return $ fmap fst eResult
35 return $ fmap fst eResult
27
36
37+-- | Similar to 'workflow', but outputs an 'Event' that fires whenever the current 'Workflow' is replaced by the next 'Workflow'.
28workflowView :: forall t m a. (Reflex t, NotReady t m, Adjustable t m, MonadFix m, MonadHold t m, PostBuild t m) => Workflow t m a -> m (Event t a)
38workflowView :: forall t m a. (Reflex t, NotReady t m, Adjustable t m, MonadFix m, MonadHold t m, PostBuild t m) => Workflow t m a -> m (Event t a)
29workflowView w0 = do
39workflowView w0 = do
30 rec eResult <- networkView . fmap unWorkflow =<< holdDyn w0 eReplace
40 rec eResult <- networkView . fmap unWorkflow =<< holdDyn w0 eReplace
31 eReplace <- fmap switch $ hold never $ fmap snd eResult
41 eReplace <- fmap switch $ hold never $ fmap snd eResult
32 return $ fmap fst eResult
42 return $ fmap fst eResult
33
43
44+-- | Map a function over a 'Workflow', possibly changing the resturn type.
34mapWorkflow :: (Reflex t, Functor m) => (a -> b) -> Workflow t m a -> Workflow t m b
45mapWorkflow :: (Reflex t, Functor m) => (a -> b) -> Workflow t m a -> Workflow t m b
35mapWorkflow f (Workflow x) = Workflow (fmap (f *** fmap (mapWorkflow f)) x)
46mapWorkflow f (Workflow x) = Workflow (fmap (f *** fmap (mapWorkflow f)) x)
36
47
48+-- | Map a "cheap" function over a 'Workflow'. Refer to the documentation for 'pushCheap' for more information and performance considerations.
37mapWorkflowCheap :: (Reflex t, Functor m) => (a -> b) -> Workflow t m a -> Workflow t m b
49mapWorkflowCheap :: (Reflex t, Functor m) => (a -> b) -> Workflow t m a -> Workflow t m b
38mapWorkflowCheap f (Workflow x) = Workflow (fmap (f *** fmapCheap (mapWorkflowCheap f)) x)
50mapWorkflowCheap f (Workflow x) = Workflow (fmap (f *** fmapCheap (mapWorkflowCheap f)) x)