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