collection icon indicating copy to clipboard operation
collection copied to clipboard

[Proposal] Add `firstWhereType`

Open SamuelGadiel opened this issue 1 year ago • 0 comments

We already have whereType, but it would be great to get the first occurrence of the given type.

Here's a use case where this could come in hand.

final results = await Future.wait(
  [
    _metadataService.getTableMetadata(tableId),
    _dataService.getTableData(tableId),
  ],
  eagerError: true,
);

final metadata = results.whereType<TableMetadata>().first;
final data = results.whereType<TableRawData>().first;

It could be replaced with

final metadata = results.firstWhereType<TableMetadata>();
final data = results.firstWhereType<TableRawData>();

SamuelGadiel avatar Jun 13 '24 14:06 SamuelGadiel