-- | Lifted functions from "Data.ByteString.Char8" that are related to standard
-- streams.
-- Like the original module, you probably want to import this module qualified
-- to avoid name clashes with the functions provided by "Prelude", e.g.:
--
-- > import Data.ByteString (ByteString)
-- > import qualified Data.ByteString.Char8 as BS8
-- > import Effectful.Console.ByteString (Console)
-- > import qualified Effectful.Console.ByteString as Console
--
module Effectful.Console.ByteString
  ( -- * Effect
    Console

    -- ** Handlers
  , runConsole

    -- * Operations
  , getLine
  , getContents
  , putStr
  , putStrLn
  , interact
  ) where

import Prelude hiding
  ( getContents
  , getLine
  , interact
  , putStr
  , putStrLn
  )

import Data.ByteString (ByteString)
import Data.ByteString.Char8 qualified as BS8

import Effectful
import Effectful.Console.Effect
import Effectful.Dispatch.Static

-- | Lifted 'BS8.getLine'.
getLine :: Console :> es => Eff es ByteString
getLine :: forall (es :: [Effect]). (Console :> es) => Eff es ByteString
getLine = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ IO ByteString
BS8.getLine

-- | Lifted 'BS8.getContents'.
getContents :: Console :> es => Eff es ByteString
getContents :: forall (es :: [Effect]). (Console :> es) => Eff es ByteString
getContents = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ IO ByteString
BS8.getContents

-- | Lifted 'BS8.putStr'.
putStr :: Console :> es => ByteString -> Eff es ()
putStr :: forall (es :: [Effect]). (Console :> es) => ByteString -> Eff es ()
putStr = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IO ()
BS8.putStr

-- | Lifted 'BS8.putStrLn'.
putStrLn :: Console :> es => ByteString -> Eff es ()
putStrLn :: forall (es :: [Effect]). (Console :> es) => ByteString -> Eff es ()
putStrLn = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IO ()
BS8.putStrLn

-- | Lifted 'BS8.interact'.
interact :: Console :> es => (ByteString -> ByteString) -> Eff es ()
interact :: forall (es :: [Effect]).
(Console :> es) =>
(ByteString -> ByteString) -> Eff es ()
interact = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> ((ByteString -> ByteString) -> IO ())
-> (ByteString -> ByteString)
-> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> ByteString) -> IO ()
BS8.interact