Selaa lähdekoodia

Iterator.forEach tweak

David Sehnal 7 vuotta sitten
vanhempi
commit
c8d0cfc493
1 muutettua tiedostoa jossa 3 lisäystä ja 3 poistoa
  1. 3 3
      src/mol-data/iterator.ts

+ 3 - 3
src/mol-data/iterator.ts

@@ -107,11 +107,11 @@ namespace Iterator {
     export function map<T, R>(base: Iterator<T>, f: (v: T) => R): Iterator<R> { return new MapIteratorImpl(base, f); }
     export function filter<T>(base: Iterator<T>, p: (v: T) => boolean): Iterator<T> { return new FilterIteratorImpl(base, p); }
 
-    // f can return non-undefined falsy value to stop the iteration.
-    export function forEach<T, Ctx>(it: Iterator<T>, f: (v: T, ctx: Ctx) => boolean | void, ctx: Ctx): Ctx {
+    // Iterate until first truthy value is returned.
+    export function forEach<T, Ctx>(it: Iterator<T>, f: (v: T, ctx: Ctx) => any, ctx: Ctx): Ctx {
         while (it.hasNext) {
             const c = f(it.move(), ctx);
-            if (typeof c !== 'undefined' && !c) return ctx;
+            if (c) return ctx;
         }
         return ctx;
     }