From 43e5132e026af1051f364477c627021341d4c045 Mon Sep 17 00:00:00 2001 From: narumincho <16481886+narumincho@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:13:44 +0900 Subject: [PATCH] feat: allow zip method different type --- lib/src/ilist/ilist.dart | 2 +- test/ilist/ilist_test.dart | 12 ++++++++++++ 2 files changed, 13 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..d4d4892 100644 --- a/test/ilist/ilist_test.dart +++ b/test/ilist/ilist_test.dart @@ -1567,6 +1567,18 @@ 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", () {