Explorar o código

Replaced direct value manipulations with functions from `defs`.

Eugene Lazutkin %!s(int64=3) %!d(string=hai) anos
pai
achega
772a38ba7f
Modificáronse 2 ficheiros con 11 adicións e 11 borrados
  1. 5 5
      src/fun.js
  2. 6 6
      src/gen.js

+ 5 - 5
src/fun.js

@@ -15,12 +15,12 @@ const next = async (value, fns, index, collect) => {
         cleanIndex = i - 1;
         throw new defs.Stop();
       }
-      if (value && value[defs.finalSymbol] === 1) {
-        collect(value.value);
+      if (defs.isFinalValue(value)) {
+        collect(defs.getFinalValue(value));
         break;
       }
-      if (value && value[defs.manySymbol] === 1) {
-        const values = value.values;
+      if (defs.isMany(value)) {
+        const values = defs.getManyValues(value);
         if (i == fns.length) {
           values.forEach(val => collect(val));
         } else {
@@ -65,7 +65,7 @@ const next = async (value, fns, index, collect) => {
 const flush = async (fns, index, collect) => {
   for (let i = index; i < fns.length; ++i) {
     const f = fns[i];
-    if (f[defs.flushSymbol] === 1) {
+    if (defs.isFlushable(f)) {
       await next(f(defs.none), fns, i + 1, collect);
     }
   }

+ 6 - 6
src/gen.js

@@ -10,12 +10,12 @@ const next = async function* (value, fns, index) {
     }
     if (value === defs.none) break;
     if (value === defs.stop) throw new defs.Stop();
-    if (value && value[defs.finalSymbol] === 1) {
-      yield value.value;
+    if (defs.isFinalValue(value)) {
+      yield defs.getFinalValue(value);
       break;
     }
-    if (value && value[defs.manySymbol] === 1) {
-      const values = value.values;
+    if (defs.isMany(value)) {
+      const values = defs.getManyValues(value);
       if (i == fns.length) {
         yield* values;
       } else {
@@ -68,13 +68,13 @@ const gen = (...fns) => {
       flushed = true;
       for (let i = 0; i < fns.length; ++i) {
         const f = fns[i];
-        if (f[defs.flushSymbol] === 1) {
+        if (defs.isFlushable(f)) {
           yield* next(f(defs.none), fns, i + 1);
         }
       }
     }
   };
-  const needToFlush = fns.some(fn => fn[defs.flushSymbol] === 1);
+  const needToFlush = fns.some(fn => defs.isFlushable(fn));
   if (needToFlush) g = defs.flushable(g);
   return defs.setFunctionList(g, fns);
 };