From 817d0846beae01c2ced4bf2dccf2645f45c14283 Mon Sep 17 00:00:00 2001 From: narumincho <16481886+narumincho@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:27:46 +0900 Subject: [PATCH 1/2] feat: allow zip method different type --- lib/src/ilist/ilist.dart | 2 +- test/ilist/ilist_test.dart | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/src/ilist/ilist.dart b/lib/src/ilist/ilist.dart index 4f67f65..11fdc3f 100644 --- a/lib/src/ilist/ilist.dart +++ b/lib/src/ilist/ilist.dart @@ -1795,7 +1795,7 @@ abstract class IList // ignore: must_be_immutable Iterable.generate(length, (index) => (index, _l[index])).toIList(config); /// Aggregate two sources trimming by the shortest source - Iterable<(T, T)> zip(Iterable otherIterable) { + Iterable<(T, U)> zip(Iterable otherIterable) { final other = otherIterable.toList(); final minLength = min(length, other.length); return Iterable.generate(minLength, (index) => (_l[index], other[index])).toIList(config); diff --git a/test/ilist/ilist_test.dart b/test/ilist/ilist_test.dart index ae42cac..20c85cc 100644 --- a/test/ilist/ilist_test.dart +++ b/test/ilist/ilist_test.dart @@ -1567,6 +1567,17 @@ void main() { ('France', 'Paris'), ('Germany', 'Berlin'), ])); + + // different type + final Iterable<(String, int)> zipped = countries.zip([10, 20, 30, 40]); + expect( + zipped, + IList([ + ('France', 10), + ('Germany', 20), + ('Brazil', 30), + ('Japan', 40) + ])); }); test("ZipAll with another source replacing with fill method value if available or else null", () { From e4e878959461d99c4be6ca787fb6a2c7d5ceef33 Mon Sep 17 00:00:00 2001 From: narumincho <16481886+narumincho@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:32:10 +0900 Subject: [PATCH 2/2] fix variable name --- test/ilist/ilist_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ilist/ilist_test.dart b/test/ilist/ilist_test.dart index 20c85cc..411d697 100644 --- a/test/ilist/ilist_test.dart +++ b/test/ilist/ilist_test.dart @@ -1569,9 +1569,9 @@ void main() { ])); // different type - final Iterable<(String, int)> zipped = countries.zip([10, 20, 30, 40]); + final Iterable<(String, int)> zippedWithInt = countries.zip([10, 20, 30, 40]); expect( - zipped, + zippedWithInt, IList([ ('France', 10), ('Germany', 20),