mirror of https://github.com/codefeathers/fuse
Muthu Kumar
7 years ago
2 changed files with 18 additions and 13 deletions
@ -1 +1 @@ |
|||
testscript.js |
|||
testscript*.js |
@ -1,16 +1,21 @@ |
|||
'use strict'; |
|||
|
|||
const Select = (value, resolve) => ({ |
|||
value, |
|||
for: (test, fn) => { |
|||
if (resolve) return { |
|||
...Select(value, resolve), |
|||
resolve |
|||
}; |
|||
if (test) return Select(value, fn); |
|||
return Select(value); |
|||
}, |
|||
resolve: resolve ? resolve : () => undefined |
|||
}); |
|||
const isIterable = val => typeof val === "object" && Symbol.iterator in val; |
|||
|
|||
class Select { |
|||
constructor(value, resolve) { |
|||
this.value = value; |
|||
this.iterable = isIterable(value); |
|||
if (resolve) this.resolve = resolve; |
|||
} |
|||
|
|||
for(test, consequent) { |
|||
if (test(this.value)) return new Select(this.value, consequent); |
|||
if (this.resolve) return this; |
|||
return this; |
|||
} |
|||
} |
|||
|
|||
Select.prototype.resolve = () => null; |
|||
|
|||
module.exports = Select; |
|||
|
Loading…
Reference in new issue