Safe Haskell | None |
---|
Control.Lens based extractors for Layout
- text :: Prism' Layout Text
- name :: Traversal' Layout FilePath
- names :: Traversal' Layout FilePath
- next :: Traversal' Layout Layout
- file :: FilePath -> IndexedTraversal' FilePath Layout Layout
- directory :: FilePath -> IndexedTraversal' FilePath Layout Layout
- node :: FilePath -> IndexedTraversal' FilePath Layout Layout
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 ())))
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 Filpath
s 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