Code Monkey home page Code Monkey logo

Comments (6)

Athari avatar Athari commented on May 26, 2024

Try updating YaLinqoPerf, this bug should be fixed by Athari/YaLinqoPerf@6036e3a

Or maybe I should just revert a breaking change to YaLinqo which stopped muliple enumeration from working... not that it's a good idea to enumerate multiple times.

from yalinqo.

cursedcoder avatar cursedcoder commented on May 26, 2024

@Athari so should we just create a new enum instead enumerating multiple times?

In my example I get this error every time I try to cast toArray()

from yalinqo.

Athari avatar Athari commented on May 26, 2024

@cursedcoder Why do you need to run your query multiple times? If you already called toArray once, you should just cache the result. In a rare case when your source changes every time, but query remains the same, yes, you should create queries every time. If you're unsure what to choose, please provide more information: what you query, how, and why you need to run your query multiple times.

from yalinqo.

vrestihnat avatar vrestihnat commented on May 26, 2024

In version < 2 this work:

        $x = from(array(1, 2, 3))->where('$v == 2');
        var_dump($x->count(), $x->toList());

but in version >= 2 doesn't work.
Exception is same:
Cannot traverse an already closed generator.

from yalinqo.

Athari avatar Athari commented on May 26, 2024

@vrestihnat Both $x->count() and $x->toList() traverse the list from the very beginning and filter all items. The result isn't implicitly cached. if you want to avoid doing the same work two times (and to make the latest version work), you need do it this way:

$x = from(array(1, 2, 3))->where('$v == 2')->toList();
var_dump(count($x), $x); // or var_dump(from($x)->count(), $x);

P. S. This behavior was changed in version 2.3. If you want to switch to version 2, but don't have time to update all usages now (though you should eventually if you care about performance), you can use version 2.2 or lower. Versions 2.3 and 2.4 are mostly dedicated to improving performance of sorting and some other operations. Switching from 1.* to 2.2 will considerably improve performance by itself (thanks to yielding and lambda caching).

from yalinqo.

Athari avatar Athari commented on May 26, 2024

Previously I considered rolling back the change that made double traversal impossible, but nobody seems to complain about this, so I guess this issue can be safely closed.

from yalinqo.

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.