-- |
-- Copyright  : (c) Ivan Perez, 2017
-- License    : BSD3
-- Maintainer : ivan.perez@keera.co.uk
--
-- Debug FRP networks by inspecting their behaviour inside.
module FRP.Dunai.Debug where

-- External imports
import Data.MonadicStreamFunction hiding (trace)
import Debug.Trace                (trace)

-- ** Debugging

-- | Monadic Stream Function that prints the value passing through using
-- 'trace'.
traceMSF :: Monad m
         => Show a
         => MSF m a a
traceMSF :: forall (m :: * -> *) a. (Monad m, Show a) => MSF m a a
traceMSF = forall (m :: * -> *) a. Monad m => (a -> String) -> MSF m a a
traceMSFWith forall a. Show a => a -> String
show

-- | Monadic Stream Function that prints the value passing through using
-- 'trace', and a customizable 'show' function.
traceMSFWith :: Monad m
             => (a -> String)
             -> MSF m a a
traceMSFWith :: forall (m :: * -> *) a. Monad m => (a -> String) -> MSF m a a
traceMSFWith a -> String
f = forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\a
x -> forall a. String -> a -> a
trace (a -> String
f a
x) a
x)

-- | Execute an IO action at every step, and ignore the result.
traceMSFWithIO :: (a -> IO b)
               -> MSF IO a a
traceMSFWithIO :: forall a b. (a -> IO b) -> MSF IO a a
traceMSFWithIO a -> IO b
f = forall (m :: * -> *) a b. Monad m => (a -> m b) -> MSF m a b
arrM (\a
x -> a -> IO b
f a
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return a
x)