diff rN u oldreactive/src/FRP/Reactive/PrimReactive.hs newreactive/src/FRP/Reactive/PrimReactive.hs
old

new


437  437  
438  438   This variant of 'snapshot' has 'Nothing's where @b@ changed and @a@ 
439  439   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) 
450  440  
451  441    Snapshot a reactive value whenever an event occurs and apply a 
452  442   combining function to the event and reactive's values. 
453   snapshotWith :: Ord t => 
 443  
 444   
 445   Eyal's change: Using lilac's implementation here: 
 446  snapshotWith :: forall a b c t. Ord t => 
454  447  (a > b > c) > EventG t a > ReactiveG t b > EventG t c 
455   snapshotWith f e r = joinMaybes $ fmap h (e `snap` r) 
 448  snapshotWith f (Event (Future (t, ~(v `Stepper` es)))) r = 
 449  (Event (Future (t, f v w `Stepper` es'))) 
456  450  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  
 454  skipToR :: Ord t => Time t > ReactiveG t b > ReactiveG t b 
 455  skipToR t r@(_ `Stepper` Event (Future (t', r'))) 
 456   t' <= t = skipToR t r' 
 457   otherwise = r 
 458   
 459  
459  460  
460  461    Accumulating event, starting from an initial value and a 
461  462   updatefunction event. See also 'accumR'. 