directory-layout-0.4.0.1: Declare, construct and verify directory layout

Safe HaskellNone

System.Directory.Layout.Lens

Contents

Description

Control.Lens based extractors for Layout

Synopsis

Usage

>>> :set -XOverloadedStrings
>>> import Control.Lens
>>> let layout = F "foo" (T "not empty" ()) (D "bar" (F "baz" (E ()) (F "quux" (T "something" ()) (E ()))) (F "swaks" (E ()) (E ())))

text :: Prism' Layout TextSource

Target Text from the current Layout top (if possible)

>>> layout ^? text
Nothing
>>> layout ^? file "foo" . text
Just "not empty"
>>> layout ^? directory "bar" . file "quux" . text
Just "something"

name :: Traversal' Layout FilePathSource

Target FilePath from the current Layout top (if possible)

>>> layout ^? name
Just "foo"
>>> layout ^? directory "bar" . name
Just "baz"
>>> layout ^? directory "quux" . name
Nothing
>>> layout & name .~ "boo"
F "boo" (T "not empty" ()) (D "bar" (F "baz" (E ()) (F "quux" (T "something" ()) (E ()))) (F "swaks" (E ()) (E ())))

names :: Traversal' Layout FilePathSource

Target all Filpaths from current Layout layer

>>> layout ^? names
Just "foo"
>>> layout ^.. names
["foo","bar","swaks"]
>>> layout ^.. directory "bar" . names
["baz","quux"]
>>> layout & directory "bar" . names %~ reverse
F "foo" (T "not empty" ()) (D "bar" (F "zab" (E ()) (F "xuuq" (T "something" ()) (E ()))) (F "swaks" (E ()) (E ())))

next :: Traversal' Layout LayoutSource

Target next Node

>>> layout ^? name
Just "foo"
>>> layout ^? next . name
Just "bar"
>>> layout ^? next . next . name
Just "swaks"
>>> layout ^? next . next . next . name
Nothing

file :: FilePath -> IndexedTraversal' FilePath Layout LayoutSource

Target Layout under the current Layout top if it happens to be a file

>>> layout ^? file "biz"
Nothing
>>> layout ^? file "swaks"
Just (E ())
>>> layout ^? directory "bar" . file "baz"
Just (E ())

directory :: FilePath -> IndexedTraversal' FilePath Layout LayoutSource

Target Layout under the current Layout top if it happens to be a directory

>>> layout ^? directory "foo"
Nothing
>>> layout ^? directory "bar"
Just (F "baz" (E ()) (F "quux" (T "something" ()) (E ())))

node :: FilePath -> IndexedTraversal' FilePath Layout LayoutSource

Target Layout under the current Layout top

>>> layout ^? node "foo"
Just (T "not empty" ())
>>> layout ^? node "bar"
Just (F "baz" (E ()) (F "quux" (T "something" ()) (E ())))
>>> layout ^? node "what"
Nothing