1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE RankNTypes #-}
7{-# LANGUAGE ScopedTypeVariables #-}
9module Reflex.Plan.Pure where
15import Control.Applicative
16import Control.Monad.Fix
17import Control.Monad.State
18import Data.IntMap (IntMap)
19import qualified Data.IntMap as IntMap
20import Data.IntSet (IntSet)
21import qualified Data.IntSet as IntSet
29mapToPureEvent :: IntMap a -> Event (Pure Int) a
30mapToPureEvent m = Event $ flip IntMap.lookup m
33newtype PurePlan a = PurePlan { unPlan :: StateT IntSet TimeM a } deriving (Functor, Applicative, Monad, MonadFix)
35liftPlan :: TimeM a -> PurePlan a
36liftPlan = PurePlan . lift
38instance MonadHold (Pure Int) PurePlan where
39 hold initial = liftPlan . hold initial
40 holdDyn initial = liftPlan . holdDyn initial
41 holdIncremental initial = liftPlan . holdIncremental initial
42 buildDynamic getInitial = liftPlan . buildDynamic getInitial
43 headE = liftPlan . headE
46instance MonadSample (Pure Int) PurePlan where
47 sample = liftPlan . sample
50instance TestPlan (Pure Int) PurePlan where
52 PurePlan . modify $ IntSet.union (IntMap.keysSet m)
53 return $ mapToPureEvent m
54 where m = IntMap.fromList (first fromIntegral <$> occs)
56runPure :: PurePlan a -> (a, IntSet)
57runPure (PurePlan p) = runStateT p mempty $ 0
59relevantTimes :: IntSet -> IntSet
60relevantTimes occs = IntSet.fromList [0..l + 1]
61 where l = fromMaybe 0 (fst <$> IntSet.maxView occs)
63testBehavior :: (Behavior (Pure Int) a, IntSet) -> IntMap a
64testBehavior (b, occs) = IntMap.fromSet (sample b) (relevantTimes occs)
66testEvent :: (Event (Pure Int) a, IntSet) -> IntMap (Maybe a)
67testEvent (Event readEvent, occs) = IntMap.fromSet readEvent (relevantTimes occs)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list