-- | Provides a dynamic effect for reading a handle.
--
-- @since 0.1
module Effectful.FileSystem.HandleReader.Dynamic
  ( -- * Effect
    HandleReader (..),
    openBinaryFile,
    withBinaryFile,
    hIsEOF,
    hGetBuffering,
    hIsOpen,
    hIsClosed,
    hIsReadable,
    hIsWritable,
    hIsSeekable,
    hIsTerminalDevice,
    hGetEcho,
    hWaitForInput,
    hReady,
    hGetChar,
    hGetLine,
    hGetContents,
    hGet,
    hGetSome,
    hGetNonBlocking,
    hLockRaw,
    hTryLockRaw,
    hUnlockRaw,

    -- ** Handlers
    runHandleReader,

    -- * File handles
    Handle,
    HandleMode (HandleModeRead),
    CanRead,

    -- * Locking
    -- $locking
    LockedHandle,
    Internal.liftLocked,
    withLockedFile,
    withTryLockedFile,
    hLock,
    hTryLock,
    hUnlock,

    -- ** Raw
    withLockedFileRaw,
    withTryLockedFileRaw,

    -- * UTF-8 Utils

    -- ** GetLine
    hGetLineUtf8,
    hGetLineUtf8Lenient,
    hGetLineUtf8ThrowM,

    -- ** GetContents
    hGetContentsUtf8,
    hGetContentsUtf8Lenient,
    hGetContentsUtf8ThrowM,

    -- ** Get
    hGetUtf8,
    hGetUtf8Lenient,
    hGetUtf8ThrowM,

    -- ** GetSome
    hGetSomeUtf8,
    hGetSomeUtf8Lenient,
    hGetSomeUtf8ThrowM,

    -- ** GetNonBlocking
    hGetNonBlockingUtf8,
    hGetNonBlockingUtf8Lenient,
    hGetNonBlockingUtf8ThrowM,

    -- * Re-exports
    ByteString,
    OsPath,
    Text,
    UnicodeException,
  )
where

import Control.Monad ((>=>))
import Data.ByteString (ByteString)
import Data.Text (Text)
import Data.Text.Encoding.Error (UnicodeException)
import Effectful
  ( Dispatch (Dynamic),
    DispatchOf,
    Eff,
    Effect,
    IOE,
    type (:>),
  )
import Effectful.Dispatch.Dynamic (HasCallStack, localSeqUnlift, reinterpret, send)
import Effectful.Dynamic.Utils (ShowEffect (showEffectCons))
import Effectful.Exception (bracket, bracket_)
import Effectful.FileSystem.Handle.Internal
  ( CanRead,
    Handle,
    HandleMode (HandleModeRead),
    LockedHandle,
  )
import Effectful.FileSystem.Handle.Internal qualified as Internal
import Effectful.FileSystem.HandleReader.Static qualified as Static
import FileSystem.OsPath (OsPath)
import FileSystem.UTF8 qualified as FS.UTF8
import System.IO (BufferMode)

-- | Dynamic effect for reading a handle.
--
-- @since 0.1
data HandleReader :: Effect where
  OpenBinaryFile :: OsPath -> HandleReader m (Handle HandleModeRead)
  WithBinaryFile :: OsPath -> (Handle HandleModeRead -> m a) -> HandleReader m a
  HIsEOF :: (CanRead p) => Handle p -> HandleReader m Bool
  HGetBuffering :: (CanRead p) => Handle p -> HandleReader m BufferMode
  HIsOpen :: (CanRead p) => Handle p -> HandleReader m Bool
  HIsClosed :: (CanRead p) => Handle p -> HandleReader m Bool
  HIsReadable :: (CanRead p) => Handle p -> HandleReader m Bool
  HIsWritable :: (CanRead p) => Handle p -> HandleReader m Bool
  HIsSeekable :: (CanRead p) => Handle p -> HandleReader m Bool
  HIsTerminalDevice :: (CanRead p) => Handle p -> HandleReader m Bool
  HGetEcho :: (CanRead p) => Handle p -> HandleReader m Bool
  HWaitForInput :: (CanRead p) => Handle p -> Int -> HandleReader m Bool
  HReady :: (CanRead p) => Handle p -> HandleReader m Bool
  HGetChar :: (CanRead p) => Handle p -> HandleReader m Char
  HGetLine :: (CanRead p) => Handle p -> HandleReader m ByteString
  HGetContents :: (CanRead p) => Handle p -> HandleReader m ByteString
  HGet :: (CanRead p) => Handle p -> Int -> HandleReader m ByteString
  HGetSome :: (CanRead p) => Handle p -> Int -> HandleReader m ByteString
  HGetNonBlocking :: (CanRead p) => Handle p -> Int -> HandleReader m ByteString
  HLockRaw :: (CanRead p) => Handle p -> HandleReader m ()
  HTryLockRaw :: (CanRead p) => Handle p -> HandleReader m Bool
  HUnlockRaw :: (CanRead p) => Handle p -> HandleReader m ()

-- | @since 0.1
type instance DispatchOf HandleReader = Dynamic

-- | @since 0.1
instance ShowEffect HandleReader where
  showEffectCons :: forall (m :: * -> *) a. HandleReader m a -> String
showEffectCons = \case
    OpenBinaryFile OsPath
_ -> String
"OpenBinaryFile"
    WithBinaryFile {} -> String
"WithBinaryFile"
    HIsEOF Handle p
_ -> String
"HIsEOF"
    HGetBuffering Handle p
_ -> String
"HGetBuffering"
    HIsOpen Handle p
_ -> String
"HIsOpen"
    HIsClosed Handle p
_ -> String
"HIsClosed"
    HIsReadable Handle p
_ -> String
"HIsReadable"
    HIsWritable Handle p
_ -> String
"HIsWritable"
    HIsSeekable Handle p
_ -> String
"HIsSeekable"
    HIsTerminalDevice Handle p
_ -> String
"HIsTerminalDevice"
    HGetEcho Handle p
_ -> String
"HGetEcho"
    HWaitForInput Handle p
_ Int
_ -> String
"HWaitForInput"
    HReady Handle p
_ -> String
"HReady"
    HGetChar Handle p
_ -> String
"HGetChar"
    HGetLine Handle p
_ -> String
"HGetLine"
    HGetContents Handle p
_ -> String
"HGetContents"
    HGet Handle p
_ Int
_ -> String
"HGet"
    HGetSome Handle p
_ Int
_ -> String
"HGetSome"
    HGetNonBlocking Handle p
_ Int
_ -> String
"HGetNonBlocking"
    HLockRaw Handle p
_ -> String
"HLockRaw"
    HTryLockRaw Handle p
_ -> String
"HTryLockRaw"
    HUnlockRaw Handle p
_ -> String
"HUnlockRaw"

-- | Runs 'HandleReader' in 'IO'.
--
-- @since 0.1
runHandleReader ::
  ( HasCallStack,
    IOE :> es
  ) =>
  Eff (HandleReader : es) a ->
  Eff es a
runHandleReader :: forall (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, IOE :> es) =>
Eff (HandleReader : es) a -> Eff es a
runHandleReader = (Eff (HandleReader : es) a -> Eff es a)
-> EffectHandler HandleReader (HandleReader : es)
-> Eff (HandleReader : es) a
-> Eff es a
forall (e :: (* -> *) -> * -> *)
       (handlerEs :: [(* -> *) -> * -> *]) a (es :: [(* -> *) -> * -> *])
       b.
(HasCallStack, DispatchOf e ~ 'Dynamic) =>
(Eff handlerEs a -> Eff es b)
-> EffectHandler e handlerEs -> Eff (e : es) a -> Eff es b
reinterpret Eff (HandleReader : es) a -> Eff es a
forall (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, IOE :> es) =>
Eff (HandleReader : es) a -> Eff es a
Static.runHandleReader (EffectHandler HandleReader (HandleReader : es)
 -> Eff (HandleReader : es) a -> Eff es a)
-> EffectHandler HandleReader (HandleReader : es)
-> Eff (HandleReader : es) a
-> Eff es a
forall a b. (a -> b) -> a -> b
$ \LocalEnv localEs
env -> \case
  OpenBinaryFile OsPath
p -> OsPath -> Eff (HandleReader : es) (Handle 'HandleModeRead)
forall (es :: [(* -> *) -> * -> *]).
(HandleReader :> es, HasCallStack) =>
OsPath -> Eff es (Handle 'HandleModeRead)
Static.openBinaryFile OsPath
p
  WithBinaryFile OsPath
p Handle 'HandleModeRead -> Eff localEs a
k -> LocalEnv localEs
-> ((forall r. Eff localEs r -> Eff (HandleReader : es) r)
    -> Eff (HandleReader : es) a)
-> Eff (HandleReader : es) a
forall (localEs :: [(* -> *) -> * -> *])
       (es :: [(* -> *) -> * -> *]) a.
HasCallStack =>
LocalEnv localEs
-> ((forall r. Eff localEs r -> Eff es r) -> Eff es a) -> Eff es a
localSeqUnlift LocalEnv localEs
env (((forall r. Eff localEs r -> Eff (HandleReader : es) r)
  -> Eff (HandleReader : es) a)
 -> Eff (HandleReader : es) a)
-> ((forall r. Eff localEs r -> Eff (HandleReader : es) r)
    -> Eff (HandleReader : es) a)
-> Eff (HandleReader : es) a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff localEs r -> Eff (HandleReader : es) r
unlift ->
    OsPath
-> (Handle 'HandleModeRead -> Eff (HandleReader : es) a)
-> Eff (HandleReader : es) a
forall (es :: [(* -> *) -> * -> *]) a.
(HandleReader :> es, HasCallStack) =>
OsPath -> (Handle 'HandleModeRead -> Eff es a) -> Eff es a
Static.withBinaryFile OsPath
p (Eff localEs a -> Eff (HandleReader : es) a
forall r. Eff localEs r -> Eff (HandleReader : es) r
unlift (Eff localEs a -> Eff (HandleReader : es) a)
-> (Handle 'HandleModeRead -> Eff localEs a)
-> Handle 'HandleModeRead
-> Eff (HandleReader : es) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle 'HandleModeRead -> Eff localEs a
k)
  HIsEOF Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hIsEOF Handle p
h
  HGetBuffering Handle p
h -> Handle p -> Eff (HandleReader : es) BufferMode
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es BufferMode
Static.hGetBuffering Handle p
h
  HIsOpen Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hIsOpen Handle p
h
  HIsClosed Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hIsClosed Handle p
h
  HIsReadable Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hIsReadable Handle p
h
  HIsWritable Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hIsWritable Handle p
h
  HIsSeekable Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hIsSeekable Handle p
h
  HIsTerminalDevice Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hIsTerminalDevice Handle p
h
  HGetEcho Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hGetEcho Handle p
h
  HWaitForInput Handle p
h Int
i -> Handle p -> Int -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Bool
Static.hWaitForInput Handle p
h Int
i
  HReady Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hReady Handle p
h
  HGetChar Handle p
h -> Handle p -> Eff (HandleReader : es) Char
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Char
Static.hGetChar Handle p
h
  HGetLine Handle p
h -> Handle p -> Eff (HandleReader : es) ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
Static.hGetLine Handle p
h
  HGetContents Handle p
h -> Handle p -> Eff (HandleReader : es) ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
Static.hGetContents Handle p
h
  HGet Handle p
h Int
i -> Handle p -> Int -> Eff (HandleReader : es) ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
Static.hGet Handle p
h Int
i
  HGetSome Handle p
h Int
i -> Handle p -> Int -> Eff (HandleReader : es) ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
Static.hGetSome Handle p
h Int
i
  HGetNonBlocking Handle p
h Int
i -> Handle p -> Int -> Eff (HandleReader : es) ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
Static.hGetNonBlocking Handle p
h Int
i
  HLockRaw Handle p
h -> Handle p -> Eff (HandleReader : es) ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
Static.hLockRaw Handle p
h
  HTryLockRaw Handle p
h -> Handle p -> Eff (HandleReader : es) Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
Static.hTryLockRaw Handle p
h
  HUnlockRaw Handle p
h -> Handle p -> Eff (HandleReader : es) ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
Static.hUnlockRaw Handle p
h

-- | Lifted 'IO.openBinaryFile'.
--
-- @since 0.1
openBinaryFile ::
  ( HandleReader :> es,
    HasCallStack
  ) =>
  OsPath ->
  Eff es (Handle HandleModeRead)
openBinaryFile :: forall (es :: [(* -> *) -> * -> *]).
(HandleReader :> es, HasCallStack) =>
OsPath -> Eff es (Handle 'HandleModeRead)
openBinaryFile = HandleReader (Eff es) (Handle 'HandleModeRead)
-> Eff es (Handle 'HandleModeRead)
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) (Handle 'HandleModeRead)
 -> Eff es (Handle 'HandleModeRead))
-> (OsPath -> HandleReader (Eff es) (Handle 'HandleModeRead))
-> OsPath
-> Eff es (Handle 'HandleModeRead)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> HandleReader (Eff es) (Handle 'HandleModeRead)
forall (m :: * -> *).
OsPath -> HandleReader m (Handle 'HandleModeRead)
OpenBinaryFile

-- | Lifted 'IO.withBinaryFile'.
--
-- @since 0.1
withBinaryFile ::
  ( HandleReader :> es,
    HasCallStack
  ) =>
  OsPath ->
  (Handle HandleModeRead -> Eff es a) ->
  Eff es a
withBinaryFile :: forall (es :: [(* -> *) -> * -> *]) a.
(HandleReader :> es, HasCallStack) =>
OsPath -> (Handle 'HandleModeRead -> Eff es a) -> Eff es a
withBinaryFile OsPath
p = HandleReader (Eff es) a -> Eff es a
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) a -> Eff es a)
-> ((Handle 'HandleModeRead -> Eff es a)
    -> HandleReader (Eff es) a)
-> (Handle 'HandleModeRead -> Eff es a)
-> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath
-> (Handle 'HandleModeRead -> Eff es a) -> HandleReader (Eff es) a
forall (m :: * -> *) a.
OsPath -> (Handle 'HandleModeRead -> m a) -> HandleReader m a
WithBinaryFile OsPath
p

-- | Lifted 'IO.hIsEof'.
--
-- @since 0.1
hIsEOF ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsEOF :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsEOF = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HIsEOF

-- | Lifted 'IO.hGetBuffering'.
--
-- @since 0.1
hGetBuffering ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es BufferMode
hGetBuffering :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es BufferMode
hGetBuffering = HandleReader (Eff es) BufferMode -> Eff es BufferMode
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) BufferMode -> Eff es BufferMode)
-> (Handle p -> HandleReader (Eff es) BufferMode)
-> Handle p
-> Eff es BufferMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) BufferMode
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m BufferMode
HGetBuffering

-- | Lifted 'IO.hIsOpen'.
--
-- @since 0.1
hIsOpen ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsOpen :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsOpen = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HIsOpen

-- | Lifted 'IO.hIsClosed'.
--
-- @since 0.1
hIsClosed ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsClosed :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsClosed = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HIsClosed

-- | Lifted 'IO.hIsReadable'.
--
-- @since 0.1
hIsReadable ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsReadable :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsReadable = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HIsReadable

-- | Lifted 'IO.hIsWritable'.
--
-- @since 0.1
hIsWritable ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsWritable :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsWritable = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HIsWritable

-- | Lifted 'IO.hIsSeekable'.
--
-- @since 0.1
hIsSeekable ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsSeekable :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsSeekable = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HIsSeekable

-- | Lifted 'IO.hIsTerminalDevice'.
--
-- @since 0.1
hIsTerminalDevice ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsTerminalDevice :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsTerminalDevice = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HIsTerminalDevice

-- | Lifted 'IO.hGetEcho'.
--
-- @since 0.1
hGetEcho ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hGetEcho :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hGetEcho = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HGetEcho

-- | Lifted 'IO.hWaitForInput'.
--
-- @since 0.1
hWaitForInput ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Bool
hWaitForInput :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Bool
hWaitForInput Handle p
h = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Int -> HandleReader (Eff es) Bool) -> Int -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> Int -> HandleReader m Bool
HWaitForInput Handle p
h

-- | Lifted 'IO.hReady'.
--
-- @since 0.1
hReady ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hReady :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hReady = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HReady

-- | Lifted 'IO.hGetChar'.
--
-- @since 0.1
hGetChar ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Char
hGetChar :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Char
hGetChar = HandleReader (Eff es) Char -> Eff es Char
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Char -> Eff es Char)
-> (Handle p -> HandleReader (Eff es) Char)
-> Handle p
-> Eff es Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Char
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Char
HGetChar

-- | Lifted 'BS.hGetLine'.
--
-- @since 0.1
hGetLine ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es ByteString
hGetLine :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine = HandleReader (Eff es) ByteString -> Eff es ByteString
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) ByteString -> Eff es ByteString)
-> (Handle p -> HandleReader (Eff es) ByteString)
-> Handle p
-> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) ByteString
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m ByteString
HGetLine

-- | Lifted 'BS.hGetContents'.
--
-- @since 0.1
hGetContents ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es ByteString
hGetContents :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetContents = HandleReader (Eff es) ByteString -> Eff es ByteString
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) ByteString -> Eff es ByteString)
-> (Handle p -> HandleReader (Eff es) ByteString)
-> Handle p
-> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) ByteString
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m ByteString
HGetContents

-- | Lifted 'BS.hGet'.
--
-- @since 0.1
hGet ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es ByteString
hGet :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
h = HandleReader (Eff es) ByteString -> Eff es ByteString
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) ByteString -> Eff es ByteString)
-> (Int -> HandleReader (Eff es) ByteString)
-> Int
-> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> HandleReader (Eff es) ByteString
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> Int -> HandleReader m ByteString
HGet Handle p
h

-- | Lifted 'BS.hGetSome'.
--
-- @since 0.1
hGetSome ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es ByteString
hGetSome :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
h = HandleReader (Eff es) ByteString -> Eff es ByteString
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) ByteString -> Eff es ByteString)
-> (Int -> HandleReader (Eff es) ByteString)
-> Int
-> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> HandleReader (Eff es) ByteString
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> Int -> HandleReader m ByteString
HGetSome Handle p
h

-- | Lifted 'BS.hGetNonBlocking'.
--
-- @since 0.1
hGetNonBlocking ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es ByteString
hGetNonBlocking :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
h = HandleReader (Eff es) ByteString -> Eff es ByteString
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) ByteString -> Eff es ByteString)
-> (Int -> HandleReader (Eff es) ByteString)
-> Int
-> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> HandleReader (Eff es) ByteString
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> Int -> HandleReader m ByteString
HGetNonBlocking Handle p
h

-- | Attempts to shared lock a file, blocking or throwing an exception
-- upon failure.
--
-- @since 0.1
hLockRaw ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p -> Eff es ()
hLockRaw :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw = HandleReader (Eff es) () -> Eff es ()
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) () -> Eff es ())
-> (Handle p -> HandleReader (Eff es) ()) -> Handle p -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) ()
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m ()
HLockRaw

-- | Attempts to shared lock a file.
--
-- @since 0.1
hTryLockRaw ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p -> Eff es Bool
hTryLockRaw :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw = HandleReader (Eff es) Bool -> Eff es Bool
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) Bool -> Eff es Bool)
-> (Handle p -> HandleReader (Eff es) Bool)
-> Handle p
-> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) Bool
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m Bool
HTryLockRaw

-- | Unlocks a locked file.
--
-- @since 0.1
hUnlockRaw ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p -> Eff es ()
hUnlockRaw :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw = HandleReader (Eff es) () -> Eff es ()
forall (e :: (* -> *) -> * -> *) (es :: [(* -> *) -> * -> *]) a.
(HasCallStack, DispatchOf e ~ 'Dynamic, e :> es) =>
e (Eff es) a -> Eff es a
send (HandleReader (Eff es) () -> Eff es ())
-> (Handle p -> HandleReader (Eff es) ()) -> Handle p -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> HandleReader (Eff es) ()
forall (p :: HandleMode) (m :: * -> *).
CanRead p =>
Handle p -> HandleReader m ()
HUnlockRaw

-- $locking
--
-- These functions bring some type-safety to file locking. Consider:
--
-- @
-- main :: (HandleReader :> es) => Eff es ()
-- main = withBinaryFile path False $ \\h -> do
--   hLockRaw handle
--   bs <- readBytes @HandleModeRead h
--   hUnlockRaw handle
--   print bs
--
-- readBytes :: (CanRead p, HandleReader :> es) => Handle p -> Eff es ByteString
-- readBytes handle = hGet handle 1024
-- @
--
-- In this example, we could remove all locking logic from @main@ and
-- everything would still compile. On the other hand:
--
-- @
-- main :: (HandleReader :> es) => Eff es ()
-- main = withBinaryFile path False $ \\h -> withLockedFile h $ \\lh -> do
--   bs <- readBytes @HandleModeRead lh
--   print bs
--
-- readBytes :: (CanRead p, HandleReader :> es) => LockedHandle p -> Eff es ByteString
-- readBytes lockedHandle = liftLocked (\\h -\> hGet h 1024) lockedHandle
-- @
--
-- Removing @withLockedFile@ would cause a compilation error, since @writeBytes@
-- requires a @LockedHandle@. The idea is to write most of the program's
-- logic in terms of @LockedHandle@, using @liftLocked@ to lift @Handle@
-- functions.

-- | Like 'hLockRaw', but returns a 'LockedHandle'.
--
-- @since 0.1
hLock ::
  ( CanRead p,
    HasCallStack,
    HandleReader :> es
  ) =>
  -- | Handle to lock.
  Handle p ->
  Eff es (LockedHandle p)
hLock :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HasCallStack, HandleReader :> es) =>
Handle p -> Eff es (LockedHandle p)
hLock = (Handle p -> Eff es ()) -> Handle p -> Eff es (LockedHandle p)
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f ()) -> Handle p -> f (LockedHandle p)
Internal.liftLock Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw

-- | Like 'hTryLockRaw', but returns a 'LockedHandle' if it succeeds.
--
-- @since 0.1
hTryLock ::
  ( CanRead p,
    HasCallStack,
    HandleReader :> es
  ) =>
  -- | Handle to lock.
  Handle p ->
  Eff es (Maybe (LockedHandle p))
hTryLock :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HasCallStack, HandleReader :> es) =>
Handle p -> Eff es (Maybe (LockedHandle p))
hTryLock = (Handle p -> Eff es Bool)
-> Handle p -> Eff es (Maybe (LockedHandle p))
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f Bool) -> Handle p -> f (Maybe (LockedHandle p))
Internal.liftTryLock Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw

-- | Like 'hUnlockRaw', but returns the original handle.
--
-- @since 0.1
hUnlock ::
  ( CanRead p,
    HasCallStack,
    HandleReader :> es
  ) =>
  -- | Handle to unlock.
  LockedHandle p ->
  Eff es (Handle p)
hUnlock :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HasCallStack, HandleReader :> es) =>
LockedHandle p -> Eff es (Handle p)
hUnlock = (Handle p -> Eff es ()) -> LockedHandle p -> Eff es (Handle p)
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f ()) -> LockedHandle p -> f (Handle p)
Internal.liftUnlock Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw

-- | Runs a computation with a shared locked file.
--
-- @since 0.1
withLockedFile ::
  ( CanRead p,
    HasCallStack,
    HandleReader :> es
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Callback with locked handle.
  (LockedHandle p -> Eff es a) ->
  Eff es a
withLockedFile :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]) a.
(CanRead p, HasCallStack, HandleReader :> es) =>
Handle p -> (LockedHandle p -> Eff es a) -> Eff es a
withLockedFile = (Handle p -> Eff es ())
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es a
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]) a.
HasCallStack =>
(Handle p -> Eff es ())
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es a
Internal.withLockedFile Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw

-- | Like 'withSharedLockedFile', except the lock attempt does not block.
--
-- @since 0.1
withTryLockedFile ::
  forall p a es.
  ( CanRead p,
    HasCallStack,
    HandleReader :> es
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Handle callback.
  (LockedHandle p -> Eff es a) ->
  Eff es (Maybe a)
withTryLockedFile :: forall (p :: HandleMode) a (es :: [(* -> *) -> * -> *]).
(CanRead p, HasCallStack, HandleReader :> es) =>
Handle p -> (LockedHandle p -> Eff es a) -> Eff es (Maybe a)
withTryLockedFile = (Handle p -> Eff es Bool)
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es (Maybe a)
forall (p :: HandleMode) a (es :: [(* -> *) -> * -> *]).
HasCallStack =>
(Handle p -> Eff es Bool)
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es (Maybe a)
Internal.withTryLockedFile Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw

-- | 'withLockedFile' without 'LockedHandle'.
--
-- @since 0.1
withLockedFileRaw ::
  ( CanRead p,
    HasCallStack,
    HandleReader :> es
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Callback with locked handle.
  Eff es a ->
  Eff es a
withLockedFileRaw :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]) a.
(CanRead p, HasCallStack, HandleReader :> es) =>
Handle p -> Eff es a -> Eff es a
withLockedFileRaw Handle p
h = Eff es () -> Eff es () -> Eff es a -> Eff es a
forall (es :: [(* -> *) -> * -> *]) a b c.
Eff es a -> Eff es b -> Eff es c -> Eff es c
bracket_ (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p
h) (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw Handle p
h)

-- | 'withTryLockedFileRaw' without 'LockedHandle'.
--
-- @since 0.1
withTryLockedFileRaw ::
  forall p a es.
  ( CanRead p,
    HasCallStack,
    HandleReader :> es
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Handle callback.
  Eff es a ->
  Eff es (Maybe a)
withTryLockedFileRaw :: forall (p :: HandleMode) a (es :: [(* -> *) -> * -> *]).
(CanRead p, HasCallStack, HandleReader :> es) =>
Handle p -> Eff es a -> Eff es (Maybe a)
withTryLockedFileRaw Handle p
h Eff es a
m =
  Eff es (Maybe ())
-> (Maybe () -> Eff es (Maybe ()))
-> (Maybe () -> Eff es (Maybe a))
-> Eff es (Maybe a)
forall (es :: [(* -> *) -> * -> *]) a b c.
Eff es a -> (a -> Eff es b) -> (a -> Eff es c) -> Eff es c
bracket
    ( do
        locked <- Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p
h
        pure $
          if locked
            then Just ()
            else Nothing
    )
    ((() -> Eff es ()) -> Maybe () -> Eff es (Maybe ())
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (Eff es () -> () -> Eff es ()
forall a b. a -> b -> a
const (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw Handle p
h)))
    ((() -> Eff es a) -> Maybe () -> Eff es (Maybe a)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (Eff es a -> () -> Eff es a
forall a b. a -> b -> a
const Eff es a
m))

-- | 'hGetLine' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetLineUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es (Either UnicodeException Text)
hGetLineUtf8 :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es (Either UnicodeException Text)
hGetLineUtf8 = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Handle p -> Eff es ByteString)
-> Handle p
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine

-- | 'hGetLine' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetLineUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetLineUtf8Lenient :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetLineUtf8Lenient = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Handle p -> Eff es ByteString) -> Handle p -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine

-- | 'hGetLine' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetLineUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetLineUtf8ThrowM :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetLineUtf8ThrowM = Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine (Handle p -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Handle p -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGetContents' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetContentsUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es (Either UnicodeException Text)
hGetContentsUtf8 :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es (Either UnicodeException Text)
hGetContentsUtf8 = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Handle p -> Eff es ByteString)
-> Handle p
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetContents

-- | 'hGetContents' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetContentsUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetContentsUtf8Lenient :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetContentsUtf8Lenient = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Handle p -> Eff es ByteString) -> Handle p -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetContents

-- | 'hGetContents' and 'decodeUtf8ThrowM'.
--
-- @since 0.1
hGetContentsUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetContentsUtf8ThrowM :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetContentsUtf8ThrowM = Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetContents (Handle p -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Handle p -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGet' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es (Either UnicodeException Text)
hGetUtf8 :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es (Either UnicodeException Text)
hGetUtf8 Handle p
h = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Int -> Eff es ByteString)
-> Int
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
h

-- | 'hGet' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetUtf8Lenient :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetUtf8Lenient Handle p
h = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Int -> Eff es ByteString) -> Int -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
h

-- | 'hGet' and 'decodeUtf8ThrowM'.
--
-- @since 0.1
hGetUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetUtf8ThrowM :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetUtf8ThrowM Handle p
h = Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
h (Int -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Int -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGetSome' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetSomeUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es (Either UnicodeException Text)
hGetSomeUtf8 :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es (Either UnicodeException Text)
hGetSomeUtf8 Handle p
h = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Int -> Eff es ByteString)
-> Int
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
h

-- | 'hGetSome' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetSomeUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetSomeUtf8Lenient :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetSomeUtf8Lenient Handle p
h = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Int -> Eff es ByteString) -> Int -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
h

-- | 'hGetSome' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetSomeUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetSomeUtf8ThrowM :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetSomeUtf8ThrowM Handle p
h = Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
h (Int -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Int -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGetNonBlocking' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetNonBlockingUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es (Either UnicodeException Text)
hGetNonBlockingUtf8 :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es (Either UnicodeException Text)
hGetNonBlockingUtf8 Handle p
h = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Int -> Eff es ByteString)
-> Int
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
h

-- | 'hGetNonBlocking' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetNonBlockingUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetNonBlockingUtf8Lenient :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetNonBlockingUtf8Lenient Handle p
h = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Int -> Eff es ByteString) -> Int -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
h

-- | 'hGetNonBlocking' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetNonBlockingUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetNonBlockingUtf8ThrowM :: forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetNonBlockingUtf8ThrowM Handle p
h = Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [(* -> *) -> * -> *]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
h (Int -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Int -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM