riptide v0.2.79 Riptide.Mutation
Link to this section Summary
Types
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.
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
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.
A map containing a path to be added (merge) and a path to be removed (delete).
Link to this section Functions
Applies the entire mutation to the input map.
Example
iex> Riptide.Mutation.apply( ...> %{"b" => false}, ...> %{delete: %{}, merge: %{"a" => true}} ...> ) %{"a" => true, "b" => false}
chunk(stream, count)
Combines two mutations into one.
Example
iex> Riptide.Mutation.combine( ...> %{delete: %{}, merge: %{"a" => true}}, ...> %{delete: %{}, merge: %{"b" => false}} ...> ) %{delete: %{}, merge: %{"a" => true, "b" => false}}
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}}}}
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}}
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
}
}
}
}
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
}
}
}
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}}}
Creates a new mutation with empty delete and merge maps.
Example
iex> Riptide.Mutation.new %{delete: %{}, merge: %{}}