Permalink
Browse files

shared count

  • Loading branch information...
1 parent 66f4e7a commit 76b05288684aae887e73e7d7a6138793c71358a3 @gelisam committed Jul 11, 2014
Showing with 18 additions and 1 deletion.
  1. +18 −1 Main.hs
View
19 Main.hs
@@ -33,8 +33,25 @@ reactiveMain floats events = return pictures
buttonClicks :: [Event t ()]
buttonClicks = map (flip buttonClick events) buttons
+ labelledClicks :: [Event t Char]
+ labelledClicks = zipWith (fmap . const) ['a'..] buttonClicks
+
+ clickLabels :: Event t Char
+ clickLabels = foldr union never labelledClicks
+
+ clickEvents :: Event t (Char, Int)
+ clickEvents = accumE (undefined, 0) (fmap mkEvent clickLabels)
+
+ mkEvent :: Char -> (Char, Int) -> (Char, Int)
+ mkEvent label (_, n) = (label, n+1)
+
countA,countB,countC :: Behavior t Int
- [countA,countB,countC] = map countEventsB buttonClicks
+ [countA,countB,countC] = map countN "abc"
+
+ countN :: Char -> Behavior t Int
+ countN label = stepper 0
+ $ fmap snd
+ $ filterE ((== label) . fst) clickEvents
clickCounts :: Behavior t (Int,Int,Int)
clickCounts = liftA3 (,,) countA countB countC

0 comments on commit 76b0528

Please sign in to comment.