Permalink
Browse files

Collection/mapCollection: preserve Discrete behavior of the mapped co…

…llection
  • Loading branch information...
1 parent d53382b commit 8932d5d6efe98b7bd68abe5d5aa5952d619fe3d2 John Lato committed May 28, 2012
Showing with 4 additions and 3 deletions.
  1. +4 −3 FRP/Euphoria/Collection.hs
View
7 FRP/Euphoria/Collection.hs
@@ -86,12 +86,13 @@ instance SignalSet (Collection k a) where
memoizeSignalSet (Collection dis)= Collection <$> memoD dis
+-- | Like 'fmap', but the Collection and interior 'Event' stream are memoized
mapCollection :: (a -> b) -> Collection k a -> SignalGen (Collection k b)
mapCollection f aC = do
- (cur,updateE) <- snapshotCollection aC
- let cur' = (fmap . fmap) f cur
+ updateE <- snd <$> snapshotCollection aC
+ newCurD <- memoD $ fmap ((fmap . fmap) f . fst) $ unCollection aC
newUpdateE <- memoE $ (fmap . fmap) f updateE
- Collection <$> (memoD $ pure (cur',newUpdateE))
+ makeCollection newCurD newUpdateE
-- | A collection whose items are created by an event, and removed by
-- another event.

0 comments on commit 8932d5d

Please sign in to comment.