withTriple method

RdfGraph withTriple(
  1. Triple triple
)

Creates a new graph with the specified triple added

Since RdfGraph is immutable, this returns a new instance with all the existing triples plus the new one. The original graph remains unchanged.

Parameters:

  • triple The triple to add to the graph

Returns: A new graph instance with the added triple

Example:

// Add a statement that John has email john@example.com
final newGraph = graph.withTriple(
  Triple(john, email, LiteralTerm.string('john@example.com'))
);

Implementation

RdfGraph withTriple(Triple triple) {
  final newTriples = List<Triple>.from(_triples)..add(triple);
  return RdfGraph(triples: newTriples);
}