Skip to content

Commit

Permalink
Add utilities for fetching lists of entities
Browse files Browse the repository at this point in the history
  • Loading branch information
abitofevrything committed Sep 23, 2024
1 parent 20443f1 commit 6f43818
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/nyxx_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export 'src/extensions/role.dart';
export 'src/extensions/scheduled_event.dart';
export 'src/extensions/snowflake_entity.dart';
export 'src/extensions/user.dart';
export 'src/extensions/list.dart';
11 changes: 11 additions & 0 deletions lib/src/extensions/list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:nyxx/nyxx.dart';

/// Extensions for fetching lists of [SnowflakeEntity]s.
extension PartialList<T extends SnowflakeEntity<T>>
on List<SnowflakeEntity<T>> {
/// Get all the entities in this list using the cached entity if possible.
Future<List<T>> get() => Future.wait(map((entity) => entity.get()));

/// Fetch all the entities in this list.
Future<List<T>> fetch() => Future.wait(map((entity) => entity.fetch()));
}

0 comments on commit 6f43818

Please sign in to comment.