module LiveCoding.Cell.Util.Internal where

-- | Helper for 'onChange'.
whenDifferent :: (Eq p, Monad m) => (p -> p -> a -> m b) -> (p, p, a) -> m (Maybe b)
whenDifferent :: (p -> p -> a -> m b) -> (p, p, a) -> m (Maybe b)
whenDifferent p -> p -> a -> m b
action (p
pOld, p
pNew, a
a)
  | p
pOld p -> p -> Bool
forall a. Eq a => a -> a -> Bool
== p
pNew = b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> m b -> m (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> p -> p -> a -> m b
action p
pOld p
pNew a
a
  | Bool
otherwise    = Maybe b -> m (Maybe b)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe b
forall a. Maybe a
Nothing