RDF.Description.get_and_update

You're seeing just the function get_and_update, go back to RDF.Description module for more information.
Link to this function

get_and_update(description, predicate, fun)

View Source

Specs

get_and_update(
  t(),
  RDF.Star.Statement.coercible_predicate(),
  ([RDF.Star.Statement.Object] -> {[RDF.Star.Statement.Object], t()} | :pop)
) :: {[RDF.Star.Statement.Object], t()}

Gets and updates the objects of the given predicate of a Description, in a single pass.

Invokes the passed function on the objects of the given predicate; this function should return either {objects_to_return, new_object} or :pop.

If the passed function returns {objects_to_return, new_objects}, the return value of get_and_update is {objects_to_return, new_description} where new_description is the input Description updated with new_objects for the given predicate.

If the passed function returns :pop the objects for the given predicate are removed and a {removed_objects, new_description} tuple gets returned.

Examples

iex> RDF.Description.new(EX.S, init: {EX.P, EX.O})
...> |> RDF.Description.get_and_update(EX.P, fn current_objects ->
...>      {current_objects, EX.New}
...>    end)
{[RDF.iri(EX.O)], RDF.Description.new(EX.S, init: {EX.P, EX.New})}
iex> RDF.Graph.new([{EX.S, EX.P1, EX.O1}, {EX.S, EX.P2, EX.O2}])
...> |> RDF.Graph.description(EX.S)
...> |> RDF.Description.get_and_update(EX.P1, fn _ -> :pop end)
{[RDF.iri(EX.O1)], RDF.Description.new(EX.S, init: {EX.P2, EX.O2})}