lens-3.8.7.3: Lenses, Folds and Traversals

Portability | Rank2Types
Stability | experimental
Maintainer | Edward Kmett <ekmett@gmail.com>
Safe Haskell | None

System.FilePath.Lens

Contents

- Operators
- Lenses

Description

Synopsis

- (</>~) :: ASetter s t FilePath FilePath -> FilePath -> s -> t
- (<</>~) :: LensLike ((,) FilePath) s a FilePath FilePath -> FilePath -> s -> (FilePath, a)
- (<.>~) :: ASetter s a FilePath FilePath -> String -> s -> a
- (<<.>~) :: LensLike ((,) FilePath) s a FilePath FilePath -> String -> s -> (FilePath, a)
- (</>=) :: MonadState s m => ASetter' s FilePath -> FilePath -> m ()
- (<</>=) :: MonadState s m => LensLike' ((,) FilePath) s FilePath -> FilePath -> m FilePath
- (<.>=) :: MonadState s m => ASetter' s FilePath -> String -> m ()
- (<<.>=) :: MonadState s m => LensLike' ((,) FilePath) s FilePath -> String -> m FilePath
- basename :: Lens' FilePath FilePath
- directory :: Lens' FilePath FilePath
- extension :: Lens' FilePath FilePath
- filename :: Lens' FilePath FilePath

# Operators

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

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)

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 -> a

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)

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 ()

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 FilePath

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 ()

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 FilePath

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 FilePath

A `Lens` for reading and writing to the basename

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

directory :: Lens' FilePath FilePath

A `Lens` for reading and writing to the directory

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

extension :: Lens' FilePath FilePath

A `Lens` for reading and writing to the extension

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

filename :: Lens' FilePath FilePath

A `Lens` for reading and writing to the full filename

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