gatherPriorArt function

Future<List<PriorArtQueryEvidence>> gatherPriorArt(
  1. PriorArtSource? source,
  2. List<String> queries
)

Every prior-art query's coverage, gathered through source — or an explicit EvidenceState.unavailable record per query when NO source is wired, and a EvidenceState.failed record per query when the batch itself threw.

Implementation

Future<List<PriorArtQueryEvidence>> gatherPriorArt(
  PriorArtSource? source,
  List<String> queries,
) async {
  List<PriorArtQueryEvidence> flat(EvidenceState state, String error) => [
    for (final query in queries)
      PriorArtQueryEvidence(
        id: boundDiscoveryEvidence(
          kind: 'prior-art-query',
          subject: query,
          source: 'search $query',
          fullText: '',
        ).id,
        query: query,
        state: state,
        error: error,
      ),
  ];
  if (source == null) {
    return flat(EvidenceState.unavailable, 'no prior-art source is composed');
  }
  try {
    return await source(queries);
  } catch (e) {
    return flat(EvidenceState.failed, '$e');
  }
}