-
-
Notifications
You must be signed in to change notification settings - Fork 914
Closed
Labels
BugSomething isn't working.Something isn't working.
Description
Description
Currently the function looks like this:
function isIteratorLike( value ) {
return (
value !== null &&
typeof value === 'object' && // too narrow
isFunction( value.next ) &&
value.next.length === 0 // too narrow
);
}ES spec requires that Type(iterator) is Object. Which includes functions.
// Type(x) is Object
typeof x === "object" ? x !== null : typeof x === "function"Then ES spec puts no restriction on next.length. Iterators created by calling generator functions have next.length === 1 because they accept an argument that becomes the result of evaluating yield.
Related Issues
Related issues # , # , and # .
Questions
No.
Demo
No response
Reproduction
var isIteratorLike = require('@stdlib/assert/is-iterator-like')
function next(arg) { return { value: ++this.v, done: this.v > 10 }}
function itor() { return Object.assign(_=>{}, { v: 0, next }) }
console.log(isIteratorLike(itor()))Expected Results
trueThat this should print true can be confirmed by checking that built-ins treat the function returned by itor() as valid iterator:
Array.from({[Symbol.iterator]: itor})Actual Results
falseVersion
@stdlib/assert 0.0.12
Environments
Node.js
Browser Version
No response
Node.js / npm Version
17.2.0
Platform
No response
Checklist
- Read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
Metadata
Metadata
Assignees
Labels
BugSomething isn't working.Something isn't working.