on 0e76993 help sign in
reflex/test/EventWriterT.hs
45 lines 1.3 kB history raw
1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE GADTs #-}
3module Main where
5import Control.Lens
6import Control.Monad
7import Data.These
9import Reflex
10import Reflex.EventWriter.Base
11import Test.Run
13main :: IO ()
14main = do
15 os1@[[Just [10,9,8,7,6,5,4,3,2,1]]] <- runApp' (unwrapApp testOrdering) $
16 [ Just ()
17 ]
18 print os1
19 os2@[[Just [1,3,5,7,9]],[Nothing,Nothing],[Just [2,4,6,8,10]],[Just [2,4,6,8,10],Nothing]]
20 <- runApp' (unwrapApp testSimultaneous) $ map Just $
21 [ This ()
22 , That ()
23 , This ()
24 , These () ()
25 ]
26 print os2
27 return ()
29unwrapApp :: (Reflex t, Monad m) => (a -> EventWriterT t [Int] m ()) -> a -> m (Event t [Int])
30unwrapApp x appIn = do
31 ((), e) <- runEventWriterT $ x appIn
32 return e
34testOrdering :: (Reflex t, Monad m) => Event t () -> EventWriterT t [Int] m ()
35testOrdering pulse = do
36 forM_ [10,9..1] $ \i -> tellEvent ([i] <$ pulse)
37 return ()
39testSimultaneous :: (Reflex t, Adjustable t m, MonadHold t m) => Event t (These () ()) -> EventWriterT t [Int] m ()
40testSimultaneous pulse = do
41 let e0 = fmapMaybe (^? here) pulse
42 e1 = fmapMaybe (^? there) pulse
43 forM_ [1,3..9] $ \i -> runWithReplace (tellEvent ([i] <$ e0)) $ ffor e1 $ \_ -> tellEvent ([i+1] <$ e0)
44 return ()