Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: packages/quiver_iterables/lib/src/zip.dart

Issue 2119523002: Added full js & js_util packages (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/quiver_iterables/lib/src/range.dart ('k') | packages/quiver_iterables/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/quiver_iterables/lib/src/zip.dart
diff --git a/packages/quiver_iterables/lib/src/zip.dart b/packages/quiver_iterables/lib/src/zip.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6e8d81bd5552819af48b2a6dbef170c57ff0a3b0
--- /dev/null
+++ b/packages/quiver_iterables/lib/src/zip.dart
@@ -0,0 +1,32 @@
+// Copyright 2013 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+part of quiver.iterables;
+
+/// Returns an [Iterable] of [List]s where the nth element in the returned
+/// iterable contains the nth element from every Iterable in [iterables]. The
+/// returned Iterable is as long as the shortest Iterable in the argument. If
+/// [iterables] is empty, it returns an empty list.
+Iterable<List> zip(Iterable<Iterable> iterables) sync* {
+ if (iterables.isEmpty) return;
+ var iterators = iterables.map((i) => i.iterator).toList(growable: false);
+ while (true) {
+ var zipped = new List(iterators.length);
+ for (var i = 0; i < zipped.length; i++) {
+ if (!iterators[i].moveNext()) return;
+ zipped[i] = iterators[i].current;
+ }
+ yield zipped;
+ }
+}
« no previous file with comments | « packages/quiver_iterables/lib/src/range.dart ('k') | packages/quiver_iterables/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698