Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterable<T>.containsAny(Iterable<T>) #41

Merged
merged 1 commit into from Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/src/iterable.dart
Expand Up @@ -172,6 +172,15 @@ extension IterableX<E> on Iterable<E> {
return true;
}

/// Checks if any elements in the specified [collection] are contained in
/// this collection.
bool containsAny(Iterable<E> collection) {
for (var element in collection) {
if (contains(element)) return true;
}
return false;
}

/// Returns true if this collection is structurally equal to the [other]
/// collection.
///
Expand Down
8 changes: 8 additions & 0 deletions test/iterable_test.dart
Expand Up @@ -164,6 +164,14 @@ void main() {
expect(list1.contentEquals(list1), true);
});

test('.containsAny()', () {
var list1 = const [1, 2, 3, 4, 5];
var list2 = const [1, 3, 6];

expect(list1.containsAny(list2), true);
expect(list2.containsAny([2, 4, 7]), false);
});

test('.contentEquals()', () {
var list1 = const ['test', 'test', 'tom', 'true'];
var list2 = const ['test', 't', 'te', 'tes'];
Expand Down