Ticket #13: snapshot.diff

File snapshot.diff, 1.7 kB (added by EyalLotem, 6 years ago)

testing a diff file

  • src/FRP/Reactive/PrimReactive.hs

    diff -rN -u old-reactive/src/FRP/Reactive/PrimReactive.hs new-reactive/src/FRP/Reactive/PrimReactive.hs
    old new  
    437437 
    438438-- This variant of 'snapshot' has 'Nothing's where @b@ changed and @a@ 
    439439-- didn't. 
    440 snap :: forall a b t. Ord t => 
    441         EventG t a -> ReactiveG t b -> EventG t (Maybe a, b) 
    442 Event (Future (Max MaxBound, _)) `snap` _ = mempty 
    443 ea `snap` (b0 `Stepper` eb) = 
    444   (Nothing, b0) `accumE` (fmap fa ea `mappend` fmap fb eb) 
    445  where 
    446    fa :: a -> Unop (Maybe a, b) 
    447    fb :: b -> Unop (Maybe a, b) 
    448    fa a (_,b) = (Just a , b) 
    449    fb b _     = (Nothing, b) 
    450440 
    451441-- | Snapshot a reactive value whenever an event occurs and apply a 
    452442-- combining function to the event and reactive's values. 
    453 snapshotWith :: Ord t => 
     443 
     444------------------------------------- 
     445-- Eyal's change: Using lilac's implementation here: 
     446snapshotWith :: forall a b c t. Ord t => 
    454447                (a -> b -> c) -> EventG t a -> ReactiveG t b -> EventG t c 
    455 snapshotWith f e r = joinMaybes $ fmap h (e `snap` r) 
     448snapshotWith f (Event (Future (t, ~(v `Stepper` es)))) r = 
     449  (Event (Future (t, f v w `Stepper` es'))) 
    456450 where 
    457    h (Nothing,_) = Nothing 
    458    h (Just a ,b) = Just (f a b) 
     451   r'@(w `Stepper` _) = skipToR t r 
     452   es' = snapshotWith f es r' 
     453 
     454skipToR :: Ord t => Time t -> ReactiveG t b -> ReactiveG t b 
     455skipToR t r@(_ `Stepper` Event (Future (t', r'))) 
     456  | t' <= t   = skipToR t r' 
     457  | otherwise = r 
     458------------------------------------- 
     459 
    459460 
    460461-- | Accumulating event, starting from an initial value and a 
    461462-- update-function event.  See also 'accumR'.