aeson-diff-generic-0.0.3: Apply a json-patch to any haskell datatype.

Safe HaskellNone
LanguageHaskell98

Data.Aeson.Diff.Generic.PathOptics

Contents

Synopsis

type synonyms

type PathLens s a = Lens' (Path, s) (Path, a) Source #

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

toKey

Methods

toKey :: Index s -> s -> Key Source #

class KeyIndexed a => Insertable a where Source #

Minimal complete definition

insertKey, deleteKey

Methods

insertKey :: Index a -> IxValue a -> a -> a Source #

deleteKey :: Index a -> a -> Maybe (IxValue a, a) Source #

class KeyIndexed a => Appendable a where Source #

Minimal complete definition

append

Methods

append :: IxValue a -> a -> a Source #

creating and extracting path optics

withPath Source #

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)

withoutPath Source #

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 #

_1P :: Field1 s s a a => PathLens s a Source #

_2P :: Field2 s s a a => PathLens s a Source #

_3P :: Field3 s s a a => PathLens s a Source #

_4P :: Field4 s s a a => PathLens s a Source #

_5P :: Field5 s s a a => PathLens s a Source #

_6P :: Field6 s s a a => PathLens s a Source #

_7P :: Field7 s s a a => PathLens s a Source #

_8P :: Field8 s s a a => PathLens s a Source #

_9P :: Field9 s s a a => PathLens s a Source #

_10P :: Field10 s s a a => PathLens s a Source #

_11P :: Field11 s s a a => PathLens s a Source #

_12P :: Field12 s s a a => PathLens s a Source #

_13P :: Field13 s s a a => PathLens s a Source #

_14P :: Field14 s s a a => PathLens s a Source #

_15P :: Field15 s s a a => PathLens s a Source #

_16P :: Field16 s s a a => PathLens s a Source #

_17P :: Field17 s s a a => PathLens s a Source #

_18P :: Field18 s s a a => PathLens s a Source #

_19P :: Field19 s s a a => PathLens s a Source #