findTriples method

List<Triple> findTriples({
  1. RdfSubject? subject,
  2. RdfPredicate? predicate,
  3. RdfObject? object,
})

Find all triples matching the given pattern

This method returns triples that match all the specified pattern components. Unlike withoutMatching, this method uses AND logic - all specified components must match. If a pattern component is null, it acts as a wildcard.

Parameters:

  • subject Optional subject to match
  • predicate Optional predicate to match
  • object Optional object to match

Returns: List of matching triples as an unmodifiable collection. The list may be empty if no matching triples exist.

Example:

// Find all statements about John
final johnsTriples = graph.findTriples(subject: john);

// Find all name statements
final nameTriples = graph.findTriples(predicate: name);

// Find John's name specifically
final johnsName = graph.findTriples(subject: john, predicate: name);

Implementation

List<Triple> findTriples({
  RdfSubject? subject,
  RdfPredicate? predicate,
  RdfObject? object,
}) {
  return List.unmodifiable(
    _triples.where((triple) {
      if (subject != null && triple.subject != subject) return false;
      if (predicate != null && triple.predicate != predicate) return false;
      if (object != null && triple.object != object) return false;
      return true;
    }),
  );
}