Questions tagged [generator]

A generator serves as a broader version of a subroutine, designed to enhance the creation of iterators. Instead of indicating a specific coroutine to transition to, the yield statement within a generator simply sends a value back to the calling routine.

What is the most effective method for utilizing the 'yield' keyword in Scala?

As I delve into writing code for my PhD research, I am transitioning to using Scala for text processing. Coming from a background in Python, I have found the 'yield' statement to be incredibly useful for creating complex iterators over large, inc ...

Changing the prototype of a generator function

TL;DR I am looking to enhance a generator function instance by adjusting its prototype, specifically the object received when calling a function*. Imagine I have a generator function: function* thing(n){ while(--n>=0) yield n; } Next, I create a ...

Avoid selecting random 8-character words

I have implemented the random module in a project, despite not being a programmer. My task involves creating a script that can generate a randomized database from an existing one. Specifically, I need the script to pick random words from a column in the "w ...

Exploring the Dynamics between Koa, Co, Bluebird, Q, Generators, Promises, and Thunks in Node.js

Exploring the development of a web application using Koa has left me with questions about when and why to choose between various "making async easier" technologies. The abundance of online information on this topic has not provided clear guidance, especial ...

Generating Vuex Getter Setter in VSCode: A simple solution

Can I quickly create vuex Getter and Setter within a computed property in VSCode (Visual Studio Code)? ...

PHP generator is capable of yielding the initial value before looping through the remaining values

I am working on this particular code snippet: <?php function generator() { yield 'First value'; for ($i = 1; $i <= 3; $i++) { yield $i; } } $gen = generator(); $first = $gen->current(); echo $first . '<br/>'; //$gen ...

What is the best method for managing an event loop during nested or recursive calculations?

When it comes to breaking a computation and releasing using setTimeout(), most examples seen involve having a shallow call stack. But what about scenarios where the computation is deeply nested or mutually-recursive, like in a tree search, with plenty of c ...

What sets Observables (Rx.js) apart from ES2015 generators?

From what I've gathered, there are various techniques used for solving asynchronous programming workflows: Callbacks (CSP) Promises Newer methods include: Rx.js Observables (or mostjs, bacon.js, xstream etc) ES6 generators Async/Await The trend seems ...

What is the syntax for accessing elements from an iterable?

Is it possible to create a getter that acts like a function generator? My attempts class Foo { * Test1(): IterableIterator<string> { // Works, but not a getter... yield "Hello!"; } * get Test2(): IterableIterator<string> ...

All installations of Yeoman generators tend to throw large amounts of errors

Encountering an issue with running generators post-installation through npm. Following the installation of yoeman, grunt, bower, and various generators, any attempt to run a generator in a new filespace (e.g., yo webapp, yo backbone) triggers multiple erro ...

Transitioning from Node.js event handling to utilizing generators

I have a specific monitor object that triggers an event whenever it detects new data, using an event handler: monitor.on("data", data => { /* do something */ }) I am interested in replacing this approach with a generator: for await(const data of moni ...

How to set up a static webdriver fixture and a generator in Pytest?

I am currently developing an automation test to detect any potential dead links in a WordPress plugin. In order to achieve this, I have implemented two helpful functions. The first function initializes a Selenium webdriver: @pytest.fixture(scope='ses ...

ES6 Generators: lack of informative stack trace when using iterator.throw(err)

The ES6 approach: iterator.throw(err) is often explained as inserting an exception as if it happened at the yield statement within the generator. The challenge lies in the fact that the stack trace of this exception does not include any information about t ...

How can generators and Q be used in the simplest fs.readFile example?

I have relied on node's async as my primary flow control mechanism for quite some time now. It has always worked well for me, without the need to delve into discussions or further reading about it. Now, I am intrigued by the possibility of using gene ...

Python's lightning-fast combinatoric generator

Currently working on a python project, I am in need of a high-speed generator function that can create all potential sets of non-negative integer numbers less than n. These sets must contain no more than s elements and the gap between the largest and small ...

A tool that enhances the visibility and readability of web languages such as HTML, PHP, and CSS

Looking to organize my own code examples, I need a way to display my code with syntax highlighting. Similar to how Symfony framework showcases it on their website: http://prntscr.com/bqrmzk. I'm wondering if there is a JavaScript framework that can a ...

How to Enhance GraphQL Mutation OutputFields with a Function Generator

I'm encountering issues while trying to incorporate a function generator within a GraphQL mutation. The function generator is utilized to streamline the promise chain inside the mutation. Prior to refactoring the code, everything was functioning corr ...