withoutTriples method
Creates a new graph with the specified triples removed
Since RdfGraph is immutable, this returns a new instance with all existing triples except those specified for removal. The original graph remains unchanged.
This method performs set subtraction - it removes all triples that exactly match those in the provided collection. Triple matching is based on exact equality of subject, predicate, and object components.
Parameters:
triples
The collection of triples to remove from the graph
Returns: A new graph instance with the specified triples removed. If none of the specified triples exist in the original graph, returns a new graph identical to the original.
Example:
// Remove multiple outdated statements about John
final updatedGraph = graph.withoutTriples([
Triple(john, email, LiteralTerm.string('old@example.com')),
Triple(john, age, LiteralTerm.integer(25))
]);
// Remove all triples from a temporary working set
final cleanGraph = graph.withoutTriples(temporaryTriples);
Implementation
RdfGraph withoutTriples(Iterable<Triple> triples) {
final newTriples = {..._triples}
..removeWhere((triple) => triples.contains(triple));
return RdfGraph(triples: newTriples.toList());
}