Skip to content

Commit

Permalink
feat: allow zip method different type
Browse files Browse the repository at this point in the history
  • Loading branch information
narumincho committed Apr 14, 2024
1 parent 00f0ba9 commit 43e5132
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/ilist/ilist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ abstract class IList<T> // 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<T> otherIterable) {
Iterable<(T, U)> zip<U>(Iterable<U> otherIterable) {
final other = otherIterable.toList();
final minLength = min(length, other.length);
return Iterable.generate(minLength, (index) => (_l[index], other[index])).toIList(config);
Expand Down
12 changes: 12 additions & 0 deletions test/ilist/ilist_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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", () {
Expand Down

0 comments on commit 43e5132

Please sign in to comment.