{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}

module System.FilePath.FilePather.ReadFilePath(
  ReadFilePathT(..)
, ReadFilePath
, ReadFilePathT1
, ReadFilePath1
, readFilePath
, swapReadFilePath
, pureReadFilePath
, liftReadFilePath
, successReadFilePath
, errorReadFilePath
, maybeReadFilePath
, tryReadFilePath
) where

import Control.Applicative ( Applicative((<*>), pure) )
import Control.Category ( Category((.)) )
import Control.Exception ( try, Exception )
import Control.Lens
    ( view,
      iso,
      swapped,
      _Wrapped,
      Field1(_1),
      Iso,
      Rewrapped,
      Wrapped(..) )
import Control.Monad
    ( join, Monad(return, (>>=)) )
import Control.Monad.Cont.Class ( MonadCont(callCC) )
import Control.Monad.Error.Class ( MonadError(throwError, catchError) )
import Control.Monad.Fail ( MonadFail(fail) )
import Control.Monad.Fix ( MonadFix(mfix) )
import Control.Monad.IO.Class ( MonadIO(liftIO) )
import Control.Monad.Morph ( MFunctor(hoist), MMonad(embed) )
import Control.Monad.Reader.Class ( MonadReader(reader, local, ask) )
import Control.Monad.State.Class ( MonadState(state, get, put) )
import Control.Monad.Trans.Class(MonadTrans(lift))
import Control.Monad.Writer.Class ( MonadWriter(pass, tell, writer, listen) )
import Control.Monad.Zip ( MonadZip(mzipWith) )
import Data.Either ( Either(..), either )
import Data.Functor ( Functor(fmap) )
import Data.Functor.Alt ( Apply((<.>)), Alt((<!>)) )
import Data.Functor.Bind ( Bind((>>-)) )
import Data.Functor.Identity( Identity(..) )
import Data.Maybe ( Maybe, maybe )
import Data.Monoid ( Monoid(mempty, mappend) )
import Data.Semigroup ( Semigroup((<>)) )
import System.FilePath ( FilePath )
import System.IO ( IO )

newtype ReadFilePathT e f a =
  ReadFilePathT (FilePath -> f (Either e a))

instance ReadFilePathT e f a ~ t =>
  Rewrapped (ReadFilePathT e' f' a') t

instance Wrapped (ReadFilePathT e f a) where
  type Unwrapped (ReadFilePathT e f a) =
    FilePath
    -> f (Either e a)
  _Wrapped' :: Iso' (ReadFilePathT e f a) (Unwrapped (ReadFilePathT e f a))
_Wrapped' =
    forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso (\(ReadFilePathT FilePath -> f (Either e a)
x) -> FilePath -> f (Either e a)
x) forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT
  {-# INLINE _Wrapped' #-}

type ReadFilePath e a =
  ReadFilePathT e Identity a

type ReadFilePathT1 e f =
  ReadFilePathT e f ()

type ReadFilePath1 e f =
  ReadFilePath e ()

readFilePath ::
  Iso
    (ReadFilePath e a)
    (ReadFilePath e' a')
    (FilePath -> Either e a)
    (FilePath -> Either e' a')
readFilePath :: forall e a e' a'.
Iso
  (ReadFilePath e a)
  (ReadFilePath e' a')
  (FilePath -> Either e a)
  (FilePath -> Either e' a')
readFilePath =
  forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
    (\(ReadFilePathT FilePath -> Identity (Either e a)
x) -> forall a. Identity a -> a
runIdentity forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> Identity (Either e a)
x)
    (\FilePath -> Either e' a'
p -> forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall a. a -> Identity a
Identity forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> Either e' a'
p))
{-# INLINE readFilePath #-}

swapReadFilePath ::
  Functor f =>
  Iso
    (ReadFilePathT e f a)
    (ReadFilePathT e' f a')
    (ReadFilePathT a f e)
    (ReadFilePathT a' f e')
swapReadFilePath :: forall (f :: * -> *) e a e' a'.
Functor f =>
Iso
  (ReadFilePathT e f a)
  (ReadFilePathT e' f a')
  (ReadFilePathT a f e)
  (ReadFilePathT a' f e')
swapReadFilePath =
  forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso
    (\ReadFilePathT e f a
r -> forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall (p :: * -> * -> *) a b c d.
Swap p =>
Iso (p a b) (p c d) (p b a) (p d c)
swapped) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped ReadFilePathT e f a
r))
    (\ReadFilePathT a' f e'
r -> forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall (p :: * -> * -> *) a b c d.
Swap p =>
Iso (p a b) (p c d) (p b a) (p d c)
swapped) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped ReadFilePathT a' f e'
r))
{-# INLINE swapReadFilePath #-}

pureReadFilePath ::
  Applicative f =>
  ReadFilePath e a
  -> ReadFilePathT e f a
pureReadFilePath :: forall (f :: * -> *) e a.
Applicative f =>
ReadFilePath e a -> ReadFilePathT e f a
pureReadFilePath =
  forall {k} (t :: (* -> *) -> k -> *) (m :: * -> *) (n :: * -> *)
       (b :: k).
(MFunctor t, Monad m) =>
(forall a. m a -> n a) -> t m b -> t n b
hoist (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. Identity a -> a
runIdentity)
{-# INLINE pureReadFilePath #-}

liftReadFilePath ::
  Applicative f =>
  (FilePath -> a)
  -> ReadFilePathT e f a
liftReadFilePath :: forall (f :: * -> *) a e.
Applicative f =>
(FilePath -> a) -> ReadFilePathT e f a
liftReadFilePath =
  forall (f :: * -> *) e a.
Applicative f =>
ReadFilePath e a -> ReadFilePathT e f a
pureReadFilePath forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
reader
{-# INLINE liftReadFilePath #-}

successReadFilePath ::
  Functor f =>
  (FilePath -> f a)
  -> ReadFilePathT e f a
successReadFilePath :: forall (f :: * -> *) a e.
Functor f =>
(FilePath -> f a) -> ReadFilePathT e f a
successReadFilePath FilePath -> f a
k =
  forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. b -> Either a b
Right forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> f a
k)
{-# INLINE successReadFilePath #-}

errorReadFilePath ::
  Functor f =>
  (FilePath -> f e)
  -> ReadFilePathT e f a
errorReadFilePath :: forall (f :: * -> *) e a.
Functor f =>
(FilePath -> f e) -> ReadFilePathT e f a
errorReadFilePath FilePath -> f e
k =
  forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. a -> Either a b
Left forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> f e
k)
{-# INLINE errorReadFilePath #-}

maybeReadFilePath ::
  Functor f =>
  (FilePath -> f (Maybe a))
  -> ReadFilePathT () f a
maybeReadFilePath :: forall (f :: * -> *) a.
Functor f =>
(FilePath -> f (Maybe a)) -> ReadFilePathT () f a
maybeReadFilePath FilePath -> f (Maybe a)
k =
  forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a b. a -> Either a b
Left ()) forall a b. b -> Either a b
Right) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> f (Maybe a)
k)
{-# INLINE maybeReadFilePath #-}

tryReadFilePath ::
  Exception e =>
  (FilePath -> IO a)
  -> ReadFilePathT e IO a
tryReadFilePath :: forall e a.
Exception e =>
(FilePath -> IO a) -> ReadFilePathT e IO a
tryReadFilePath FilePath -> IO a
k =
  forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall e a. Exception e => IO a -> IO (Either e a)
try forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> IO a
k)
{-# INLINE tryReadFilePath #-}

instance (Monad f, Semigroup a) => Semigroup (ReadFilePathT e f a) where
  ReadFilePathT FilePath -> f (Either e a)
x <> :: ReadFilePathT e f a -> ReadFilePathT e f a -> ReadFilePathT e f a
<> ReadFilePathT FilePath -> f (Either e a)
y =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> FilePath -> f (Either e a)
x FilePath
p forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (\a
a -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a
a forall a. Semigroup a => a -> a -> a
<>)) (FilePath -> f (Either e a)
y FilePath
p)))
  {-# INLINE (<>) #-}

instance (Monad f, Monoid a) => Monoid (ReadFilePathT e f a) where
  mappend :: ReadFilePathT e f a -> ReadFilePathT e f a -> ReadFilePathT e f a
mappend =
    forall a. Semigroup a => a -> a -> a
(<>)
  {-# INLINE mappend #-}
  mempty :: ReadFilePathT e f a
mempty =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty)))
  {-# INLINE mempty #-}

instance Functor f => Functor (ReadFilePathT e f) where
  fmap :: forall a b. (a -> b) -> ReadFilePathT e f a -> ReadFilePathT e f b
fmap a -> b
f (ReadFilePathT FilePath -> f (Either e a)
x) =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f)) FilePath -> f (Either e a)
x)
  {-# INLINE fmap #-}

instance Monad f => Apply (ReadFilePathT e f) where
  ReadFilePathT FilePath -> f (Either e (a -> b))
f <.> :: forall a b.
ReadFilePathT e f (a -> b)
-> ReadFilePathT e f a -> ReadFilePathT e f b
<.> ReadFilePathT FilePath -> f (Either e a)
k =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> FilePath -> f (Either e (a -> b))
f FilePath
p forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (\a -> b
a -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
a) (FilePath -> f (Either e a)
k FilePath
p)))
  {-# INLINE (<.>) #-}

instance Monad f => Bind (ReadFilePathT e f) where
  ReadFilePathT FilePath -> f (Either e a)
f >>- :: forall a b.
ReadFilePathT e f a
-> (a -> ReadFilePathT e f b) -> ReadFilePathT e f b
>>- a -> ReadFilePathT e f b
g =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> FilePath -> f (Either e a)
f FilePath
p forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (\a
a -> forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (a -> ReadFilePathT e f b
g a
a) FilePath
p))
  {-# INLINE (>>-) #-}

instance Monad f => Applicative (ReadFilePathT e f) where
  <*> :: forall a b.
ReadFilePathT e f (a -> b)
-> ReadFilePathT e f a -> ReadFilePathT e f b
(<*>) =
    forall (f :: * -> *) a b. Apply f => f (a -> b) -> f a -> f b
(<.>)
  pure :: forall a. a -> ReadFilePathT e f a
pure =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure

instance Monad f => Alt (ReadFilePathT e f) where
  ReadFilePathT FilePath -> f (Either e a)
a <!> :: forall a.
ReadFilePathT e f a -> ReadFilePathT e f a -> ReadFilePathT e f a
<!> ReadFilePathT FilePath -> f (Either e a)
b =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> FilePath -> f (Either e a)
a FilePath
p forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure (FilePath -> f (Either e a)
b FilePath
p)) (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure))
  {-# INLINE (<!>) #-}

instance Monad f => Monad (ReadFilePathT e f) where
  >>= :: forall a b.
ReadFilePathT e f a
-> (a -> ReadFilePathT e f b) -> ReadFilePathT e f b
(>>=) =
    forall (m :: * -> *) a b. Bind m => m a -> (a -> m b) -> m b
(>>-)
  {-# INLINE (>>=) #-}
  return :: forall a. a -> ReadFilePathT e f a
return =
    forall (f :: * -> *) a. Applicative f => a -> f a
pure
  {-# INLINE return #-}

instance MonadTrans (ReadFilePathT e) where
  lift :: forall (m :: * -> *) a. Monad m => m a -> ReadFilePathT e m a
lift =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure
  {-# INLINE lift #-}

instance MonadIO f => MonadIO (ReadFilePathT e f) where
  liftIO :: forall a. IO a -> ReadFilePathT e f a
liftIO =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. Applicative f => a -> f a
pure
  {-# INLINE liftIO #-}

instance MFunctor (ReadFilePathT e) where
  hoist :: forall (m :: * -> *) (n :: * -> *) b.
Monad m =>
(forall a. m a -> n a)
-> ReadFilePathT e m b -> ReadFilePathT e n b
hoist forall a. m a -> n a
k (ReadFilePathT FilePath -> m (Either e b)
f) =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall a. m a -> n a
k forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.FilePath -> m (Either e b)
f)
  {-# INLINE hoist #-}

instance MMonad (ReadFilePathT e) where
  embed :: forall (n :: * -> *) (m :: * -> *) b.
Monad n =>
(forall a. m a -> ReadFilePathT e n a)
-> ReadFilePathT e m b -> ReadFilePathT e n b
embed forall a. m a -> ReadFilePathT e n a
k (ReadFilePathT FilePath -> m (Either e b)
f) =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (forall a. m a -> ReadFilePathT e n a
k (FilePath -> m (Either e b)
f FilePath
p)) FilePath
p))
  {-# INLINE embed #-}

instance Monad f => MonadReader FilePath (ReadFilePathT e f) where
  ask :: ReadFilePathT e f FilePath
ask =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure)
  {-# INLINE ask #-}
  local :: forall a.
(FilePath -> FilePath)
-> ReadFilePathT e f a -> ReadFilePathT e f a
local FilePath -> FilePath
k (ReadFilePathT FilePath -> f (Either e a)
f) =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (FilePath -> f (Either e a)
f forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> FilePath
k)
  {-# INLINE local #-}
  reader :: forall a. (FilePath -> a) -> ReadFilePathT e f a
reader FilePath -> a
k =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> a
k)
  {-# INLINE reader #-}

instance MonadState FilePath f => MonadState FilePath (ReadFilePathT e f) where
  state :: forall a. (FilePath -> (a, FilePath)) -> ReadFilePathT e f a
state =
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state
  {-# INLINE state #-}
  get :: ReadFilePathT e f FilePath
get =
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall s (m :: * -> *). MonadState s m => m s
get
  {-# INLINE get #-}
  put :: FilePath -> ReadFilePathT e f ()
put =
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall s (m :: * -> *). MonadState s m => s -> m ()
put
  {-# INLINE put #-}

instance MonadWriter FilePath f => MonadWriter FilePath (ReadFilePathT e f) where
  writer :: forall a. (a, FilePath) -> ReadFilePathT e f a
writer =
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall w (m :: * -> *) a. MonadWriter w m => (a, w) -> m a
writer
  {-# INLINE writer #-}
  tell :: FilePath -> ReadFilePathT e f ()
tell =
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell
  {-# INLINE tell #-}
  listen :: forall a. ReadFilePathT e f a -> ReadFilePathT e f (a, FilePath)
listen (ReadFilePathT FilePath -> f (Either e a)
f) =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
a -> (a
a, FilePath
p))) (FilePath -> f (Either e a)
f FilePath
p))
  {-# INLINE listen #-}
  pass :: forall a.
ReadFilePathT e f (a, FilePath -> FilePath) -> ReadFilePathT e f a
pass (ReadFilePathT FilePath -> f (Either e (a, FilePath -> FilePath))
f) =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t a b. Field1 s t a b => Lens s t a b
_1)) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. FilePath -> f (Either e (a, FilePath -> FilePath))
f)
  {-# INLINE pass #-}

instance MonadFail f => MonadFail (ReadFilePathT e f) where
  fail :: forall a. FilePath -> ReadFilePathT e f a
fail =
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail
  {-# INLINE fail #-}

instance MonadFix f => MonadFix (ReadFilePathT e f) where
  mfix :: forall a. (a -> ReadFilePathT e f a) -> ReadFilePathT e f a
mfix a -> ReadFilePathT e f a
f =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> forall (m :: * -> *) a. MonadFix m => (a -> m a) -> m a
mfix (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (\a
a -> forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (a -> ReadFilePathT e f a
f a
a) FilePath
p)))
  {-# INLINE mfix #-}

instance MonadZip f => MonadZip (ReadFilePathT e f) where
  mzipWith :: forall a b c.
(a -> b -> c)
-> ReadFilePathT e f a
-> ReadFilePathT e f b
-> ReadFilePathT e f c
mzipWith a -> b -> c
f (ReadFilePathT FilePath -> f (Either e a)
m) (ReadFilePathT FilePath -> f (Either e b)
n) =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
p -> FilePath -> f (Either e a)
m FilePath
p forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left) (\a
a -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> b -> c
f a
a)) (FilePath -> f (Either e b)
n FilePath
p)))
  {-# INLINE mzipWith #-}

instance MonadCont f => MonadCont (ReadFilePathT e f) where
  callCC :: forall a b.
((a -> ReadFilePathT e f b) -> ReadFilePathT e f a)
-> ReadFilePathT e f a
callCC (a -> ReadFilePathT e f b) -> ReadFilePathT e f a
p =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\FilePath
r -> forall (m :: * -> *) a b. MonadCont m => ((a -> m b) -> m a) -> m a
callCC (\Either e a -> f (Either e b)
c -> forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped ((a -> ReadFilePathT e f b) -> ReadFilePathT e f a
p (forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Either e a -> f (Either e b)
c forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure)) FilePath
r))
  {-# INLINE callCC #-}

instance MonadError e f => MonadError e (ReadFilePathT e f) where
  throwError :: forall a. e -> ReadFilePathT e f a
throwError =
    forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
  {-# INLINE throwError #-}
  catchError :: forall a.
ReadFilePathT e f a
-> (e -> ReadFilePathT e f a) -> ReadFilePathT e f a
catchError (ReadFilePathT FilePath -> f (Either e a)
f) e -> ReadFilePathT e f a
g =
    forall e (f :: * -> *) a.
(FilePath -> f (Either e a)) -> ReadFilePathT e f a
ReadFilePathT (\ FilePath
r -> forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
catchError (FilePath -> f (Either e a)
f FilePath
r) (\ e
e -> forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall s t. Rewrapping s t => Iso s t (Unwrapped s) (Unwrapped t)
_Wrapped (e -> ReadFilePathT e f a
g e
e) FilePath
r))
  {-# INLINE catchError #-}