lens-4.4.0.1: Lenses, Folds and Traversals

PortabilityRank2Types
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Inferred

System.FilePath.Lens

Contents

Description

 

Synopsis

Operators

(</>~) :: ASetter s t FilePath FilePath -> FilePath -> s -> tSource

Modify the path by adding another path.

>>> both </>~ "bin" $ ("hello","world")
("hello/bin","world/bin")
 (</>~) :: Setter s a FilePath FilePath -> FilePath -> s -> a
 (</>~) :: Iso s a FilePath FilePath -> FilePath -> s -> a
 (</>~) :: Lens s a FilePath FilePath -> FilePath -> s -> a
 (</>~) :: Traversal s a FilePath FilePath -> FilePath -> s -> a

(<</>~) :: LensLike ((,) FilePath) s a FilePath FilePath -> FilePath -> s -> (FilePath, a)Source

Add a path onto the end of the target of a Lens and return the result

When you do not need the result of the operation, (</>~) is more flexible.

(<.>~) :: ASetter s a FilePath FilePath -> String -> s -> aSource

Modify the path by adding extension.

>>> both <.>~ "txt" $ ("hello","world")
("hello.txt","world.txt")
 (<.>~) :: Setter s a FilePath FilePath -> String -> s -> a
 (<.>~) :: Iso s a FilePath FilePath -> String -> s -> a
 (<.>~) :: Lens s a FilePath FilePath -> String -> s -> a
 (<.>~) :: Traversal s a FilePath FilePath -> String -> s -> a

(<<.>~) :: LensLike ((,) FilePath) s a FilePath FilePath -> String -> s -> (FilePath, a)Source

Add an extension onto the end of the target of a Lens and return the result

>>> _1 <<.>~ "txt" $ ("hello","world")
("hello.txt",("hello.txt","world"))

When you do not need the result of the operation, (<.>~) is more flexible.

(</>=) :: MonadState s m => ASetter' s FilePath -> FilePath -> m ()Source

Modify the target(s) of a Simple Lens, Iso, Setter or Traversal by adding a path.

>>> execState (both </>= "bin") ("hello","world")
("hello/bin","world/bin")
 (</>=) :: MonadState s m => Setter' s FilePath -> FilePath -> m ()
 (</>=) :: MonadState s m => Iso' s FilePath -> FilePath -> m ()
 (</>=) :: MonadState s m => Lens' s FilePath -> FilePath -> m ()
 (</>=) :: MonadState s m => Traversal' s FilePath -> FilePath -> m ()

(<</>=) :: MonadState s m => LensLike' ((,) FilePath) s FilePath -> FilePath -> m FilePathSource

Add a path onto the end of the target of a Lens into your monad's state and return the result.

When you do not need the result of the operation, (</>=) is more flexible.

(<.>=) :: MonadState s m => ASetter' s FilePath -> String -> m ()Source

Modify the target(s) of a Simple Lens, Iso, Setter or Traversal by adding an extension.

>>> execState (both <.>= "txt") ("hello","world")
("hello.txt","world.txt")
 (<.>=) :: MonadState s m => Setter' s FilePath -> String -> m ()
 (<.>=) :: MonadState s m => Iso' s FilePath -> String -> m ()
 (<.>=) :: MonadState s m => Lens' s FilePath -> String -> m ()
 (<.>=) :: MonadState s m => Traversal' s FilePath -> String -> m ()

(<<.>=) :: MonadState s m => LensLike' ((,) FilePath) s FilePath -> String -> m FilePathSource

Add an extension onto the end of the target of a Lens into your monad's state and return the result.

>>> evalState (_1 <<.>= "txt") ("hello","world")
"hello.txt"

When you do not need the result of the operation, (<.>=) is more flexible.

Lenses

basename :: Lens' FilePath FilePathSource

A Lens for reading and writing to the basename

Note: This is not a legal Lens unless the outer FilePath has both a directory and filename component and the generated basenames are not null and contain no directory separators.

>>> basename .~ "filename" $ "path/name.png"
"path/filename.png"

directory :: Lens' FilePath FilePathSource

A Lens for reading and writing to the directory

Note: this is not a legal Lens unless the outer FilePath already has a directory component, and generated directories are not null.

>>> "long/path/name.txt" ^. directory
"long/path"

extension :: Lens' FilePath FilePathSource

A Lens for reading and writing to the extension

Note: This is not a legal Lens, unless you are careful to ensure that generated extension FilePath components are either null or start with extSeparator and do not contain any internal extSeparators.

>>> extension .~ ".png" $ "path/name.txt"
"path/name.png"

filename :: Lens' FilePath FilePathSource

A Lens for reading and writing to the full filename

Note: This is not a legal Lens, unless you are careful to ensure that generated filename FilePath components are not null and do not contain any elements of pathSeparatorss.

>>> filename .~ "name.txt" $ "path/name.png"
"path/name.txt"