varying 0.1.0.3 → 0.1.1.0
raw patch · 3 files changed
+31/−4 lines, 3 files
Files
- src/Control/Varying/Core.hs +8/−2
- src/Control/Varying/Event.hs +22/−1
- varying.cabal +1/−1
src/Control/Varying/Core.hs view
@@ -37,7 +37,8 @@ testVar_, testWhile_, vtrace,- vstrace+ vstrace,+ vftrace, ) where import Prelude hiding (id, (.))@@ -142,7 +143,12 @@ -- | Trace the sample value of a 'Var' with a prefix and pass the sample along -- as output. This is very useful for debugging graphs of 'Var's. vstrace :: (Applicative a, Show b) => String -> Var a b b-vstrace s = var $ \b -> trace (s ++ show b) b+vstrace s = vftrace ((s ++) . show)++-- | Trace the sample value after being run through a "show" function.+-- This is very useful for debugging graphs of 'Var's.+vftrace :: Applicative a => (b -> String) -> Var a b b+vftrace f = var $ \b -> trace (f b) b -- | A utility function for testing 'Var's that don't require input. Runs -- a 'Var' printing each sample until the given predicate fails.
src/Control/Varying/Event.hs view
@@ -34,6 +34,7 @@ toEvent, -- * Using event streams collect,+ collectWith, hold, holdWith, startingWith,@@ -55,6 +56,8 @@ andThenWith, andThenE, switchByMode,+ onlyWhen,+ onlyWhenE, -- * Combining event streams combineWith, combine@@ -187,7 +190,8 @@ Event a' -> f a' b in return (b', Var $ \a' -> collect' b' a') --- | Collect all produced values into a list.+-- | Collect all produced values into a list. The latest event value will+-- be at the head of the list. collect :: Monad m => Var m (Event a) [a] collect = collectWith (:) @@ -347,6 +351,23 @@ where vOf eb = case eb of NoEvent -> v Event b -> f b++-- | Produce event values only when the input value passes the predicate.+-- Maintains state when 'cold'.+onlyWhen :: Monad m => Var m a b -> (a -> Bool) -> Var m a (Event b)+onlyWhen v f = v `onlyWhenE` hot+ where hot = var id ~> onWhen f++-- | Produce event values from the first signal only when an event is+-- produced by the second signal.+-- Maintains state when 'cold'.+onlyWhenE :: Monad m => Var m a b -> Var m a (Event c) -> Var m a (Event b)+onlyWhenE v hot = Var $ \a -> do+ (e, hot') <- runVar hot a+ if isEvent e+ then do (b, v') <- runVar v a+ return (Event b, onlyWhenE v' hot')+ else return (NoEvent, onlyWhenE v hot') -------------------------------------------------------------------------------- -- Combining event streams --------------------------------------------------------------------------------
varying.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.1.0.3+version: 0.1.1.0 -- A short (one-line) description of the package. synopsis: Automaton based varying values, event streams and tweening.