Comparing version 0.1.3 to 0.1.4
36
fx.js
@@ -109,26 +109,21 @@ export const | ||
L.flat = L.flatten = function(iter) { | ||
iter = iter[Symbol.iterator](); | ||
let flatting = null; | ||
L.flat = L.flatten = function(iter, depth = 1) { | ||
const iterStack = [iter[Symbol.iterator]()]; | ||
return { | ||
next: function recur() { | ||
if (flatting) { | ||
const cur = flatting.next(); | ||
if (!cur.done) return cur; | ||
flatting = null; | ||
} | ||
const iter = last(iterStack); | ||
if (!iter) return { done: true }; | ||
const cur = iter.next(); | ||
if (cur.done) return cur; | ||
if (hasIter(cur.value)) { | ||
flatting = cur.value[Symbol.iterator](); | ||
if (cur.done) { | ||
iterStack.pop(); | ||
return recur(); | ||
} else if (iterStack.length <= depth && isIterable(cur.value) && typeof cur.value != 'string') { | ||
iterStack.push(cur.value[Symbol.iterator]()); | ||
return recur(); | ||
} else if (cur.value instanceof Promise) { | ||
return { | ||
value: cur.value.then(value => { | ||
if (!hasIter(value)) return value; | ||
flatting = value[Symbol.iterator](); | ||
const cur = flatting.next(); | ||
return cur.done ? Promise.reject(nop) : cur.value; | ||
if (iterStack.length > depth || !isIterable(value) || typeof value == 'string') return value; | ||
const iter = value[Symbol.iterator](), cur = iter.next(); | ||
return cur.done ? Promise.reject(nop) : (iterStack.push(iter), cur.value); | ||
}), | ||
@@ -145,8 +140,3 @@ done: false | ||
L.deepFlat = L.deep_flat = L.deepFlatten = L.deep_flatten = function *f(iter) { | ||
for (const a of iter) { | ||
if (typeof a != 'string' && hasIter(a)) yield *f(a); | ||
else yield a; | ||
} | ||
}; | ||
L.deepFlat = L.deep_flat = L.deepFlatten = L.deep_flatten = iter => L.flat(iter, Infinity); | ||
@@ -153,0 +143,0 @@ L.flatMap = L.flat_map = curry((f, iter) => L.flat(L.map(f, iter))); |
{ | ||
"name": "fxjs2", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Functional Extensions for Javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16169
399