module System.FilePath.Lens
(
(</>~), (<</>~), (<<</>~), (<.>~), (<<.>~), (<<<.>~)
, (</>=), (<</>=), (<<</>=), (<.>=), (<<.>=), (<<<.>=)
, basename, directory, extension, filename
) where
import Prelude ()
import Control.Monad.State as State
import System.FilePath
( (</>), (<.>), splitExtension
, takeBaseName, takeDirectory
, takeExtension, takeFileName
)
import Control.Lens.Internal.Prelude
import Control.Lens hiding ((<.>))
infixr 4 </>~, <</>~, <<</>~, <.>~, <<.>~, <<<.>~
infix 4 </>=, <</>=, <<</>=, <.>=, <<.>=, <<<.>=
(</>~) :: ASetter s t FilePath FilePath -> FilePath -> s -> t
ASetter s t FilePath FilePath
l </>~ :: ASetter s t FilePath FilePath -> FilePath -> s -> t
</>~ FilePath
n = ASetter s t FilePath FilePath -> (FilePath -> FilePath) -> s -> t
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter s t FilePath FilePath
l (FilePath -> FilePath -> FilePath
</> FilePath
n)
{-# INLINE (</>~) #-}
(</>=) :: MonadState s m => ASetter' s FilePath -> FilePath -> m ()
ASetter' s FilePath
l </>= :: ASetter' s FilePath -> FilePath -> m ()
</>= FilePath
b = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
State.modify (ASetter' s FilePath
l ASetter' s FilePath -> FilePath -> s -> s
forall s t. ASetter s t FilePath FilePath -> FilePath -> s -> t
</>~ FilePath
b)
{-# INLINE (</>=) #-}
(<</>~) :: LensLike ((,)FilePath) s a FilePath FilePath -> FilePath -> s -> (FilePath, a)
LensLike ((,) FilePath) s a FilePath FilePath
l <</>~ :: LensLike ((,) FilePath) s a FilePath FilePath
-> FilePath -> s -> (FilePath, a)
<</>~ FilePath
m = LensLike ((,) FilePath) s a FilePath FilePath
l LensLike ((,) FilePath) s a FilePath FilePath
-> (FilePath -> FilePath) -> s -> (FilePath, a)
forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (FilePath -> FilePath -> FilePath
</> FilePath
m)
{-# INLINE (<</>~) #-}
(<</>=) :: MonadState s m => LensLike' ((,)FilePath) s FilePath -> FilePath -> m FilePath
LensLike' ((,) FilePath) s FilePath
l <</>= :: LensLike' ((,) FilePath) s FilePath -> FilePath -> m FilePath
<</>= FilePath
r = LensLike' ((,) FilePath) s FilePath
l LensLike' ((,) FilePath) s FilePath
-> (FilePath -> FilePath) -> m FilePath
forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (FilePath -> FilePath -> FilePath
</> FilePath
r)
{-# INLINE (<</>=) #-}
(<<</>~) :: Optical' (->) q ((,)FilePath) s FilePath -> FilePath -> q s (FilePath, s)
Optical' (->) q ((,) FilePath) s FilePath
l <<</>~ :: Optical' (->) q ((,) FilePath) s FilePath
-> FilePath -> q s (FilePath, s)
<<</>~ FilePath
b = Optical' (->) q ((,) FilePath) s FilePath
l Optical' (->) q ((,) FilePath) s FilePath
-> Optical' (->) q ((,) FilePath) s FilePath
forall a b. (a -> b) -> a -> b
$ \FilePath
a -> (FilePath
a, FilePath
a FilePath -> FilePath -> FilePath
</> FilePath
b)
{-# INLINE (<<</>~) #-}
(<<</>=) :: MonadState s m => LensLike' ((,)FilePath) s FilePath -> FilePath -> m FilePath
LensLike' ((,) FilePath) s FilePath
l <<</>= :: LensLike' ((,) FilePath) s FilePath -> FilePath -> m FilePath
<<</>= FilePath
b = LensLike' ((,) FilePath) s FilePath
l LensLike' ((,) FilePath) s FilePath
-> (FilePath -> (FilePath, FilePath)) -> m FilePath
forall k s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \FilePath
a -> (FilePath
a, FilePath
a FilePath -> FilePath -> FilePath
</> FilePath
b)
{-# INLINE (<<</>=) #-}
(<.>~) :: ASetter s a FilePath FilePath -> String -> s -> a
ASetter s a FilePath FilePath
l <.>~ :: ASetter s a FilePath FilePath -> FilePath -> s -> a
<.>~ FilePath
n = ASetter s a FilePath FilePath -> (FilePath -> FilePath) -> s -> a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter s a FilePath FilePath
l (FilePath -> FilePath -> FilePath
<.> FilePath
n)
{-# INLINE (<.>~) #-}
(<.>=) :: MonadState s m => ASetter' s FilePath -> String -> m ()
ASetter' s FilePath
l <.>= :: ASetter' s FilePath -> FilePath -> m ()
<.>= FilePath
b = (s -> s) -> m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
State.modify (ASetter' s FilePath
l ASetter' s FilePath -> FilePath -> s -> s
forall s t. ASetter s t FilePath FilePath -> FilePath -> s -> t
<.>~ FilePath
b)
{-# INLINE (<.>=) #-}
(<<.>~) :: LensLike ((,)FilePath) s a FilePath FilePath -> String -> s -> (FilePath, a)
LensLike ((,) FilePath) s a FilePath FilePath
l <<.>~ :: LensLike ((,) FilePath) s a FilePath FilePath
-> FilePath -> s -> (FilePath, a)
<<.>~ FilePath
m = LensLike ((,) FilePath) s a FilePath FilePath
l LensLike ((,) FilePath) s a FilePath FilePath
-> (FilePath -> FilePath) -> s -> (FilePath, a)
forall b s t a. LensLike ((,) b) s t a b -> (a -> b) -> s -> (b, t)
<%~ (FilePath -> FilePath -> FilePath
<.> FilePath
m)
{-# INLINE (<<.>~) #-}
(<<.>=) :: MonadState s m => LensLike' ((,)FilePath) s FilePath -> String -> m FilePath
LensLike' ((,) FilePath) s FilePath
l <<.>= :: LensLike' ((,) FilePath) s FilePath -> FilePath -> m FilePath
<<.>= FilePath
r = LensLike' ((,) FilePath) s FilePath
l LensLike' ((,) FilePath) s FilePath
-> (FilePath -> FilePath) -> m FilePath
forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
<%= (FilePath -> FilePath -> FilePath
<.> FilePath
r)
{-# INLINE (<<.>=) #-}
(<<<.>~) :: Optical' (->) q ((,)FilePath) s FilePath -> String -> q s (FilePath, s)
Optical' (->) q ((,) FilePath) s FilePath
l <<<.>~ :: Optical' (->) q ((,) FilePath) s FilePath
-> FilePath -> q s (FilePath, s)
<<<.>~ FilePath
b = Optical' (->) q ((,) FilePath) s FilePath
l Optical' (->) q ((,) FilePath) s FilePath
-> Optical' (->) q ((,) FilePath) s FilePath
forall a b. (a -> b) -> a -> b
$ \FilePath
a -> (FilePath
a, FilePath
a FilePath -> FilePath -> FilePath
<.> FilePath
b)
{-# INLINE (<<<.>~) #-}
(<<<.>=) :: MonadState s m => LensLike' ((,)FilePath) s FilePath -> String -> m FilePath
LensLike' ((,) FilePath) s FilePath
l <<<.>= :: LensLike' ((,) FilePath) s FilePath -> FilePath -> m FilePath
<<<.>= FilePath
b = LensLike' ((,) FilePath) s FilePath
l LensLike' ((,) FilePath) s FilePath
-> (FilePath -> (FilePath, FilePath)) -> m FilePath
forall k s (m :: * -> *) (p :: k -> * -> *) r (a :: k) b.
MonadState s m =>
Over p ((,) r) s s a b -> p a (r, b) -> m r
%%= \FilePath
a -> (FilePath
a, FilePath
a FilePath -> FilePath -> FilePath
<.> FilePath
b)
{-# INLINE (<<<.>=) #-}
basename :: Lens' FilePath FilePath
basename :: (FilePath -> f FilePath) -> FilePath -> f FilePath
basename FilePath -> f FilePath
f FilePath
p = (FilePath -> FilePath -> FilePath
<.> FilePath -> FilePath
takeExtension FilePath
p) (FilePath -> FilePath)
-> (FilePath -> FilePath) -> FilePath -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FilePath -> FilePath
takeDirectory FilePath
p FilePath -> FilePath -> FilePath
</>) (FilePath -> FilePath) -> f FilePath -> f FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> f FilePath
f (FilePath -> FilePath
takeBaseName FilePath
p)
{-# INLINE basename #-}
directory :: Lens' FilePath FilePath
directory :: (FilePath -> f FilePath) -> FilePath -> f FilePath
directory FilePath -> f FilePath
f FilePath
p = (FilePath -> FilePath -> FilePath
</> FilePath -> FilePath
takeFileName FilePath
p) (FilePath -> FilePath) -> f FilePath -> f FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> f FilePath
f (FilePath -> FilePath
takeDirectory FilePath
p)
{-# INLINE directory #-}
extension :: Lens' FilePath FilePath
extension :: (FilePath -> f FilePath) -> FilePath -> f FilePath
extension FilePath -> f FilePath
f FilePath
p = (FilePath
n FilePath -> FilePath -> FilePath
<.>) (FilePath -> FilePath) -> f FilePath -> f FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> f FilePath
f FilePath
e
where
(FilePath
n, FilePath
e) = FilePath -> (FilePath, FilePath)
splitExtension FilePath
p
{-# INLINE extension #-}
filename :: Lens' FilePath FilePath
filename :: (FilePath -> f FilePath) -> FilePath -> f FilePath
filename FilePath -> f FilePath
f FilePath
p = (FilePath -> FilePath
takeDirectory FilePath
p FilePath -> FilePath -> FilePath
</>) (FilePath -> FilePath) -> f FilePath -> f FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> f FilePath
f (FilePath -> FilePath
takeFileName FilePath
p)
{-# INLINE filename #-}