Skip to content

Commit

Permalink
Add utilities for fetching lists of entities (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
abitofevrything authored Sep 23, 2024
1 parent 2d9b97a commit a70037b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/nyxx_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ 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';
export 'src/extensions/application.dart';
10 changes: 10 additions & 0 deletions lib/src/extensions/list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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()));
}
3 changes: 2 additions & 1 deletion test/unit/sanitizer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import 'package:test/test.dart';

const _whitespaceCharacter = "‎";

final sampleContent = '<@1234> test <@!2345> test2 <@&3456> test3 <#4567> test4 <a:test_emoji:5678> test5 <:test_emoji:6789> test6 </test command:123456789123456789>';
final sampleContent =
'<@1234> test <@!2345> test2 <@&3456> test3 <#4567> test4 <a:test_emoji:5678> test5 <:test_emoji:6789> test6 </test command:123456789123456789>';
final removed = ' test test2 test3 test4 test5 test6 ';
final sanitized =
'<@${_whitespaceCharacter}1234> test <@${_whitespaceCharacter}2345> test2 <@&${_whitespaceCharacter}3456> test3 <#${_whitespaceCharacter}4567> test4 <${_whitespaceCharacter}a\\:test_emoji\\:5678> test5 <$_whitespaceCharacter\\:test_emoji\\:6789> test6 </${_whitespaceCharacter}test command:123456789123456789>';
Expand Down

0 comments on commit a70037b

Please sign in to comment.