Safe Haskell | None |
---|---|
Language | Haskell98 |
Data.Aeson.Diff.Generic.PathOptics
- type PathLens s a = Lens' (Path, s) (Path, a)
- type PathTraversal s a = Traversal' (Path, s) (Path, a)
- overPath :: ToJSON a => PathTraversal s a -> (a -> a) -> s -> (Patch, s)
- replacePath :: ToJSON a => PathTraversal s a -> a -> s -> (Patch, s)
- getPath :: PathTraversal s a -> s -> [(Pointer, a)]
- appendPath :: (ToJSON (IxValue a), Appendable a) => IxValue a -> PathTraversal s a -> s -> (Patch, s)
- insertPath :: (ToJSON (IxValue a), Insertable a) => Index a -> IxValue a -> PathTraversal s a -> s -> (Patch, s)
- deletePath :: (ToJSON (IxValue a), Insertable a) => Index a -> PathTraversal s a -> s -> (Patch, s)
- testPath :: ToJSON a => PathTraversal s a -> s -> (Patch, s)
- class KeyIndexed s where
- class KeyIndexed a => Insertable a where
- class KeyIndexed a => Appendable a where
- withPath :: Functor f => Path -> ((a -> Compose f ((,) Path) a) -> s -> Compose f ((,) Path) s) -> ((Path, a) -> f (Path, a)) -> (Path, s) -> f (Path, s)
- withoutPath :: Functor f => (((Path, a) -> f (Path, a)) -> (Path, s) -> f (Path, s)) -> (a -> f a) -> s -> f s
- ixP :: (KeyIndexed s, Ixed s) => Index s -> Traversal' (Path, s) (Path, IxValue s)
- traverseP :: (a ~ Index (s a), TraversableWithIndex a s, KeyIndexed (s a)) => Traversal' (Path, s a) (Path, a)
- _1P :: Field1 s s a a => PathLens s a
- _2P :: Field2 s s a a => PathLens s a
- _3P :: Field3 s s a a => PathLens s a
- _4P :: Field4 s s a a => PathLens s a
- _5P :: Field5 s s a a => PathLens s a
- _6P :: Field6 s s a a => PathLens s a
- _7P :: Field7 s s a a => PathLens s a
- _8P :: Field8 s s a a => PathLens s a
- _9P :: Field9 s s a a => PathLens s a
- _10P :: Field10 s s a a => PathLens s a
- _11P :: Field11 s s a a => PathLens s a
- _12P :: Field12 s s a a => PathLens s a
- _13P :: Field13 s s a a => PathLens s a
- _14P :: Field14 s s a a => PathLens s a
- _15P :: Field15 s s a a => PathLens s a
- _16P :: Field16 s s a a => PathLens s a
- _17P :: Field17 s s a a => PathLens s a
- _18P :: Field18 s s a a => PathLens s a
- _19P :: Field19 s s a a => PathLens s a
- _LeftP :: Traversal' (Path, Either a b) (Path, a)
- _RightP :: Traversal' (Path, Either a b) (Path, b)
- _JustP :: Traversal' (Path, Maybe a) (Path, a)
type synonyms
type PathTraversal s a = Traversal' (Path, s) (Path, a) Source #
operations over path optics
overPath :: ToJSON a => PathTraversal s a -> (a -> a) -> s -> (Patch, s) Source #
Modify the value(s) at the traversal, and return a patch which represents those (replace) operations.
replacePath :: ToJSON a => PathTraversal s a -> a -> s -> (Patch, s) Source #
Replace the value at the traversal, and return a patch with the replace operations.
getPath :: PathTraversal s a -> s -> [(Pointer, a)] Source #
Return the values and pointers pointed to by the traversal (if any)
appendPath :: (ToJSON (IxValue a), Appendable a) => IxValue a -> PathTraversal s a -> s -> (Patch, s) Source #
Append a value to the structure pointed by the lens. Return a patch which the append operations)
insertPath :: (ToJSON (IxValue a), Insertable a) => Index a -> IxValue a -> PathTraversal s a -> s -> (Patch, s) Source #
Insert a value at the given key, and return a patch with the insert operations
deletePath :: (ToJSON (IxValue a), Insertable a) => Index a -> PathTraversal s a -> s -> (Patch, s) Source #
Delete a value at the given key if present, and return a patch with the delete operations.
testPath :: ToJSON a => PathTraversal s a -> s -> (Patch, s) Source #
Create a patch that tests if the value at the pointer equals the current value. Returns the data unmodified.
class KeyIndexed s where Source #
Minimal complete definition
class KeyIndexed a => Insertable a where Source #
class KeyIndexed a => Appendable a where Source #
Minimal complete definition
creating and extracting path optics
Arguments
:: Functor f | |
=> Path | the path into the structure |
-> ((a -> Compose f ((,) Path) a) -> s -> Compose f ((,) Path) s) | the input optic |
-> ((Path, a) -> f (Path, a)) -> (Path, s) -> f (Path, s) | the output optic with path information |
Annotate an optic with a path. The output optic will be the same optic, with a path annotation. For example:
withPath :: Path -> Lens' s a -> Lens' (Path, s) (Path, a) withPath :: Path -> Traversal' s a -> Traversal' (Path, s) (Path, a)
Arguments
:: Functor f | |
=> (((Path, a) -> f (Path, a)) -> (Path, s) -> f (Path, s)) | input optic |
-> (a -> f a) -> s -> f s | output optic without path information |
remove the path from an optic annotated with path information.
withoutPath . withPath ≡ id
The output optic will be the same optic, without the path annotation. For example:
withoutPath :: Lens' (Path, s) (Path, a) -> Lens' s a withoutPath :: Traversal' (Path, s) (Path, a) -> Traversal' s a
pathOptics
ixP :: (KeyIndexed s, Ixed s) => Index s -> Traversal' (Path, s) (Path, IxValue s) Source #
ix
from lens annotated with a path. Provides a simple
Traversal lets you traverse the value at a given key in a Map or
element at an ordinal position in a list or Seq. Includes the path
to the element.
traverseP :: (a ~ Index (s a), TraversableWithIndex a s, KeyIndexed (s a)) => Traversal' (Path, s a) (Path, a) Source #