From ec4f3f3a53b87e8ed0770ca068f86eefece1f5f5 Mon Sep 17 00:00:00 2001 From: birjuvachhani Date: Thu, 20 Oct 2022 19:34:17 +0530 Subject: [PATCH] :fire: Remove `elementAtOrNull` extension. --- CHANGELOG.md | 1 + lib/collection/iterable.dart | 7 ------- test/iterable_test.dart | 6 ------ 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d07a0c..82bcbc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 3.1.1 - Fix `MAX_INT_VALUE` and `MIN_INT_VALUE` not compiling for JS. +- [BREAKING]: Remove `elementAtOrNull` since it is added in the `collections` package. - Upgrade dependencies. ## 3.1.0 diff --git a/lib/collection/iterable.dart b/lib/collection/iterable.dart index 6a60767..2ef4a65 100644 --- a/lib/collection/iterable.dart +++ b/lib/collection/iterable.dart @@ -417,13 +417,6 @@ extension IterableScrewDriver on Iterable { /// Alias for [subtract]. Iterable except(Iterable other) => subtract(other); - /// Equivalent to [elementAt] but returns null instead of throwing - /// [RangeError] if the index is out of bounds. - E? elementAtOrNull(int index) { - if (index < 0 || index >= length) return null; - return elementAt(index); - } - /// Returns true if the collection contains all the elements /// present in [other] collection. bool containsAll(Iterable other) => other.every(contains); diff --git a/test/iterable_test.dart b/test/iterable_test.dart index 9161582..a7aaae5 100644 --- a/test/iterable_test.dart +++ b/test/iterable_test.dart @@ -174,12 +174,6 @@ void main() { expect([1, 2, 3].except([2]), containsAllInOrder([1, 3])); expect([1, 2, 3].except([1, 5]), containsAllInOrder([2, 3])); - // elementAtOrNull tests - expect([1, 2, 3].elementAtOrNull(0), equals(1)); - expect([1, 2, 3].elementAtOrNull(2), equals(3)); - expect([1, 2, 3].elementAtOrNull(3), isNull); - expect([1, 2, 3].elementAtOrNull(-1), isNull); - // containsAll tests expect([1, 2, 3].containsAll([1, 2]), isTrue); expect([1, 2, 3].containsAll([1, 2, 3, 4]), isFalse);