GithubHelp home page GithubHelp logo

Comments (7)

vitaly-t avatar vitaly-t commented on June 26, 2024 1

It may be argued that isIteratorResult should return return has(value, 'value') || has(value, 'done'), however the bug is triggered by has implementation, which returns false for value: undefined, which is definitely incorrect.

The proper syntax goes like this: value must be always present, and done is optional. However, all JavaScript implementations feature both at all times, i.e. the last element is always {value: undefined, done: true}.

But let's look at how IteratorResult is defined within ES2015 that we are using:

interface IteratorYieldResult<TYield> {
    done?: false;
    value: TYield;
}

interface IteratorReturnResult<TReturn> {
    done: true;
    value: TReturn;
}

type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;

So we can see that done is optional while inside generators, which is odd, but ok. That's why I think that fixing has implementation is more appropriate.

@RebeccaStevens What do you think? If you agree, please make the change 😉

from iter-ops.

mattbishop avatar mattbishop commented on June 26, 2024 1

Verified fix in 2.8.0. Thanks!

from iter-ops.

vitaly-t avatar vitaly-t commented on June 26, 2024

@RebeccaStevens b.t.w., you have this comment inside has - // Cannot use in operator as it doesn't work for strings.

Perhaps hasOwnProperty is usable for this? ;)

The difference from in is as follows...

Unlike the hasOwnProperty() method, the in operator will return true for both direct and inherited properties that exist in the object or its prototype chain.

But our {value, done} is always a simple object, it is never a class ;) So the question is - are we ever use it for classes? Anyway, I'm leaving it up to you.

from iter-ops.

RebeccaStevens avatar RebeccaStevens commented on June 26, 2024

Object.prototype.hasOwnProperty (or Object.hasOwn) is usually my go to for this, but it doesn't work in this case.
In general, we need to know if the object has the key, regardless of if it's direct or inherited. Not for the case of isIteratorResult, but for the other functions such as isSyncIterable and isPromiseLike.
Additionally, that function doesn't work for symbols (Object.getOwnPropertySymbols would need to be used for symbols, but again, that's for direct symbols).

I deicide it is best to go back to using the in operator. If we convert the object to an Object first, then it should work as desired.

from iter-ops.

vitaly-t avatar vitaly-t commented on June 26, 2024

v2.8.0-beta.2 now contains the fix.

I'm gonna play a little with the new concurrencyFork operator within iter-ops-extras, to make sure it is as every bit as good as I was expecting, and then will make a proper 2.8.0 release 😉

@RebeccaStevens Never got your view on the new concurrencyFork addition (in the discussions). I think it is a game changer. What do you reckon?

from iter-ops.

RebeccaStevens avatar RebeccaStevens commented on June 26, 2024

It looks good. I'll have a more in-depth look at it a bit later.

from iter-ops.

vitaly-t avatar vitaly-t commented on June 26, 2024

The fix for this was released in v2.8.0.

@RebeccaStevens I tested it out (concurrencyFork) thoroughly, and it was good, so I have released it ;)

from iter-ops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.