Skip to content

Commit f958ca5

Browse files
committedJan 22, 2020
Add Iterable.containsAny().
Closes #40
1 parent 50bba11 commit f958ca5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
 

‎lib/src/iterable.dart

+9
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ extension IterableX<E> on Iterable<E> {
172172
return true;
173173
}
174174

175+
/// Checks if any elements in the specified [collection] are contained in
176+
/// this collection.
177+
bool containsAny(Iterable<E> collection) {
178+
for (var element in collection) {
179+
if (contains(element)) return true;
180+
}
181+
return false;
182+
}
183+
175184
/// Returns true if this collection is structurally equal to the [other]
176185
/// collection.
177186
///

‎test/iterable_test.dart

+8
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ void main() {
164164
expect(list1.contentEquals(list1), true);
165165
});
166166

167+
test('.containsAny()', () {
168+
var list1 = const [1, 2, 3, 4, 5];
169+
var list2 = const [1, 3, 6];
170+
171+
expect(list1.containsAny(list2), true);
172+
expect(list2.containsAny([2, 4, 7]), false);
173+
});
174+
167175
test('.contentEquals()', () {
168176
var list1 = const ['test', 'test', 'tom', 'true'];
169177
var list2 = const ['test', 't', 'te', 'tes'];

0 commit comments

Comments
 (0)