]> Git — Sourcephile - tmp/julm/arpeggigon.git/blob - Reactogon/Auxiliary/Auxiliary.hs
onChange function working
[tmp/julm/arpeggigon.git] / Reactogon / Auxiliary / Auxiliary.hs
1 {-# LANGUAGE Arrows #-}
2
3 module Reactogon.Auxiliary.Auxiliary where
4
5 import Data.Maybe
6 import FRP.Yampa
7
8 -- stepBack contains its previous argument as its output. Because it's
9 -- hard to define it at time 0, it's wrapped up in a Maybe.
10 stepBack :: SF a (Maybe a)
11 stepBack = sscan f (Nothing, Nothing) >>^ snd
12 where f :: (Maybe a, Maybe a) -> a -> (Maybe a, Maybe a)
13 f (Nothing,Nothing) x' = (Just x', Nothing)
14 f (Just x, _) x' = (Just x', Just x)
15
16 -- Throws an Event when the incoming signal change. The Event is
17 -- tagged with the new value.
18 onChange :: (Eq a) => SF a (Event a)
19 onChange = proc x -> do
20 x' <- stepBack -< x
21 let makeEvent x x'
22 | isNothing x' = NoEvent
23 | isJust x' = let x'' = fromJust x' in
24 if x'' == x then NoEvent else Event x
25 returnA -< makeEvent x x'