riptide v0.2.0 Riptide.Mutation

Link to this section Summary

Types

A key-value pair representing a layer of the mutation. The key

t()

A map containing a path to be added (merge) and a path to be removed (delete).

Functions

Applies the entire mutation to the input map.

Combines two mutations into one.

Adds a path to be deleted to the input mutation.

Takes two maps and returns a mutation that could be applied to turn the the first map into the second.

Accepts a list and mutation, and returns a new mutation with the given mutation nested at the given path.

Returns a map of levels for the given mutation. Each level is a key-value pair, where the key is a list of keys representing the current path, and the value is the remaining part of the mutation structure.

Places the value at the given path in the merge.

Creates a new mutation with empty delete and merge maps.

Link to this section Types

Link to this type

layer()

layer() :: {[String.t()], t()}

A key-value pair representing a layer of the mutation. The key

is a list of strings representing the path to the current layer. The value is a
mutation, representing any deeper sub-mutations.
Link to this type

t()

t() :: %{merge: map(), delete: map()}

A map containing a path to be added (merge) and a path to be removed (delete).

Link to this section Functions

Link to this function

apply(input, mutation)

apply(map(), t()) :: map()

Applies the entire mutation to the input map.

Example

iex> Riptide.Mutation.apply(
...>    %{"b" => false},
...>    %{delete: %{}, merge: %{"a" => true}}
...> )
%{"a" => true, "b" => false}
Link to this function

chunk(stream, count)

Link to this function

combine(input)

combine(Enum.t()) :: t()
Link to this function

combine(left, right)

combine(t(), t()) :: t()

Combines two mutations into one.

Example

iex> Riptide.Mutation.combine(
...>    %{delete: %{}, merge: %{"a" => true}},
...>    %{delete: %{}, merge: %{"b" => false}}
...> )
%{delete: %{}, merge: %{"a" => true, "b" => false}}
Link to this function

delete(input, path)

delete(t(), [String.t()]) :: t()

Adds a path to be deleted to the input mutation.

Example

iex> Riptide.Mutation.delete(
...>    %{
...>        delete: %{},
...>        merge: %{
...>            "a" => %{
...>                "b" => %{
...>                    "c" => true
...>                }
...>            }
...>        }
...>    },
...>    ["c"]
...> )
%{delete: %{"c" => 1}, merge: %{"a" => %{"b" => %{"c" => true}}}}
Link to this function

from_diff(old, new)

Takes two maps and returns a mutation that could be applied to turn the the first map into the second.

Example

iex> Riptide.Mutation.from_diff(
...>    %{"a" => 1},
...>    %{"b" => 2}
...>)
%{delete: %{"a" => 1}, merge: %{"b" => 2}}
Link to this function

inflate(path, mut)

inflate([String.t()], t()) :: t()

Accepts a list and mutation, and returns a new mutation with the given mutation nested at the given path.

Example

iex> Riptide.Mutation.inflate(
...>    ["a", "b"],
...>    %{
...>        delete: %{},
...>        merge: %{
...>            "a" => 1
...>        }
...>    }
...>)
%{
    delete: %{
        "a" => %{
            "b" => %{}
        }
    },
    merge: %{
        "a" => %{
            "b" => %{
                "a" => 1
            }
        }
    }
}
Link to this function

layers(map)

layers(t()) :: %{required([String.t()]) => layer()}

Returns a map of levels for the given mutation. Each level is a key-value pair, where the key is a list of keys representing the current path, and the value is the remaining part of the mutation structure.

Example

iex> %{delete: %{}, merge: %{"a" => %{"b" => true}}} |> Riptide.Mutation.layers
%{
    [] => %{
        delete: %{},
        merge: %{
            "a" => %{
                "b" => true
            }
        }
    },
    ["a"] => %{
        delete: %{},
        merge: %{
            "b" => true
        }
    }
}
Link to this function

merge(input, path, value)

merge(t(), [String.t()], any()) :: t()

Places the value at the given path in the merge.

Example

iex> mutation = %{delete: %{}, merge: %{"a" => %{"b" => 1}}}
iex> Riptide.Mutation.merge(mutation, ["a","c"], 2)
%{delete: %{}, merge: %{"a" => %{"b" => 1, "c" => 2}}}
Link to this function

new(merge \\ %{}, delete \\ %{})

new(map(), map()) :: t()

Creates a new mutation with empty delete and merge maps.

Example

iex> Riptide.Mutation.new
%{delete: %{}, merge: %{}}