-- | This module defines the 'DynamicWriter' class.
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
#ifdef USE_REFLEX_OPTIMIZER
{-# OPTIONS_GHC -fplugin=Reflex.Optimizer #-}
#endif
module Reflex.DynamicWriter.Class
  ( MonadDynamicWriter
  , DynamicWriter(..)
  ) where

import Control.Monad.Reader (ReaderT, lift)
import Reflex.Class (Dynamic)

{-# DEPRECATED MonadDynamicWriter "Use 'DynamicWriter' instead" #-}
-- | Type synonym for 'DynamicWriter'
type MonadDynamicWriter = DynamicWriter

-- | 'MonadDynamicWriter' efficiently collects 'Dynamic' values using 'tellDyn'
-- and combines them monoidally to provide a 'Dynamic' result.
class (Monad m, Monoid w) => DynamicWriter t w m | m -> t w where
  tellDyn :: Dynamic t w -> m ()

instance DynamicWriter t w m => DynamicWriter t w (ReaderT r m) where
  tellDyn :: Dynamic t w -> ReaderT r m ()
tellDyn = m () -> ReaderT r m ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ReaderT r m ())
-> (Dynamic t w -> m ()) -> Dynamic t w -> ReaderT r m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dynamic t w -> m ()
forall t w (m :: * -> *).
DynamicWriter t w m =>
Dynamic t w -> m ()
tellDyn