module CabalGild.Class.MonadWrite where

import qualified Data.ByteString as ByteString

-- | A 'Monad' that can also write output, either to standard output (STDOUT)
-- or to a file.
class (Monad m) => MonadWrite m where
  -- | Writes output to the given file, or to STDOUT if the given file is
  -- 'Nothing'.
  write :: Maybe FilePath -> ByteString.ByteString -> m ()

-- | Uses 'ByteString.putStr' or 'ByteString.writeFile'.
instance MonadWrite IO where
  write :: Maybe FilePath -> ByteString -> IO ()
write = (ByteString -> IO ())
-> (FilePath -> ByteString -> IO ())
-> Maybe FilePath
-> ByteString
-> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ByteString -> IO ()
ByteString.putStr FilePath -> ByteString -> IO ()
ByteString.writeFile