yield-keyword Questions

9

Solved

I've recently stumbled over this code: function xrange($min, $max) { for ($i = $min; $i <= $max; $i++) { yield $i; } } I've never seen this yield keyword before. Trying to run the code I ...
Hannie asked 5/7, 2013 at 7:53

2

This is kind of a weird question so I'll explain: I have a generator like this that is acting as a generator frontend to an IRC server: def irc_iter(): # not the real code, simplified msgs = get...
Tillandsia asked 25/2, 2014 at 23:59

2

Solved

I am trying to understand the behaviour of the yield statement by building a generator which behaves similarly to the 'enumerate' built-in function but I am witnessing inconsistencies depending on ...
Toot asked 18/6, 2018 at 14:11

5

Solved

This is my piece of code with two generators defined: one_line_gen = (x for x in range(3)) def three_line_gen(): yield 0 yield 1 yield 2 When I execute: for x in one_line_gen: print x for...
Pouched asked 30/7, 2017 at 12:51

8

Solved

I encountered the following Ruby code: class MyClass attr_accessor :items ... def each @items.each{|item| yield item} end ... end What does the each method do? In particular, I don't under...
Serving asked 1/12, 2010 at 6:17

1

Solved

I have an action called initialiseApp which, obviously, initialises the application. There are some things I need from the server, such as the user information, the styles and some details about th...
Orel asked 22/12, 2016 at 12:16

4

Solved

Consider the following code. std::vector<result_data> do_processing() { pqxx::result input_data = get_data_from_database(); return process_data(input_data); } std::vector<result_data&g...
Sparky asked 10/8, 2012 at 9:17

4

Solved

In Python, I have many times seen the yield function used to create a generator. Both this and the print function technically both perform the action of methods because they return a value. However...
Depreciate asked 17/7, 2015 at 3:41

1

I am novice in Python and programming. Generators are a bit too complicated to understand for new programmers. Here's my theory on generator functions in Python: Any function contains a yield st...
Cohobate asked 10/8, 2014 at 19:43

1

Has anyone tried to get Underscore JS or lodash (or any ES5 standard functions for that matter) working with generators? If we have an array var myArray = [1,2,3,4,6]; We want to forEach over it. ...
Countertenor asked 26/7, 2014 at 3:41

1

Javascript generator cannot help too much since it is not a real coroutine. So I hope to have coroutine in browser using some new ecmascript 6 keyword, "yield". i.e., I hope I can yield across mult...

2

I need to generate multiple results but one at a time, as opposed to everything at once in an array. How do I do that in Matlab with a generator like syntax as in Python?
Droughty asked 13/1, 2014 at 18:51

7

Solved

I read about the yield keyword in JavaScript and I need to use it in my project. I read that this keyword has been implemented starting from a certain version of JS so I think that old browsers don...
Samoyed asked 19/2, 2010 at 15:11

2

Solved

Can I yield a block inside a Proc? Consider this example: a = Proc.new do yield end a.call do puts "x" end What I'm trying to achieve is to print x, but interpreting this with ruby 2.0 raises...
Colver asked 23/7, 2013 at 18:27

3

Solved

I have a DateTime and TimeSpan class in Scala (assume that the < and + operators work as they should). I'm trying to define a 'range' function that takes a start/stop time and a timespan for ste...
Keratose asked 28/10, 2011 at 12:49

1

Solved

I'm studying in Python yield and find that yield is not only the way in which generators output a return value but also a way to put values into a generator. For example the following code def f()...
Platinumblond asked 5/12, 2012 at 4:58

4

Solved

In Scala language, I want to write a function that yields odd numbers within a given range. The function prints some log when iterating even numbers. The first version of the function is: def getO...
Weinstock asked 16/9, 2012 at 13:25

1

Solved

Possible Duplicate: yield statement implementation I've seen msdn docs and it says: The yield keyword signals to the compiler that the method in which it appears is an iterator blo...
Wringer asked 27/11, 2011 at 12:23

3

Solved

The yield keyword documentation says: The yield keyword signals to the compiler that the method in which it appears is an iterator block. I have encountered code using the yield keywor...
Popeyed asked 25/11, 2011 at 20:19

1

Solved

The compiler complains that resultingThing in the code below is being used before being assigned to. private IEnumerable<IThing> FindThings(dynamic spec) { if (spec == null) yield break; ...
Ancheta asked 18/5, 2011 at 22:19

3

Solved

Is it possible to use yield as an iterator without evaluation of every value? It is a common task when it is easy to implement complex list generation, and then you need to convert it into Iterato...
Leapt asked 24/12, 2010 at 9:34
1

© 2022 - 2024 — McMap. All rights reserved.