Questions tagged [yield]

yield is (1) a keyword that facilitates creation of generator functions, (2) a Ruby statement to transfer control from one coroutine to another, (3) a Java statement used to yield a value from a switch expression.

In , the yield statement is only used when defining a generator function, and is only used in the body of the generator function. Using a yield statement in a function definition is sufficient to cause that definition to create a generator function instead of a normal function.

In , the yield statement is in context of coroutines generally used to transfer control from one coroutine to another, for example from a method to a block passed into it as an argument.

’s yield return is equivalent to Python’s yield, and yield break is just return in Python. In C#, yield is used in an iterator block to provide a value to the enumerator object or to signal the end of iteration.

yield is used in and generator functions in the same way it is in Python generator functions.

In yield is used in for-comprehension construction. for-comprehension iterates over one or more collections and uses yield to create and return new collection.

In , yield is a keyword used in a statement yield: <yield-target> to yield a value, which becomes the value of the enclosing switch expression.

1730 questions
0
votes
1 answer

Scrapy output file that recursively runs all the yield requests - how to

So i have a scrapy spider as follows: class CoursesSpider(scrapy.Spider): name = "courses" start_urls = [ 'http://example.com' ] def parse(self, response): for subject in response.css('subject'): subject_name =…
Max Smith
  • 925
  • 1
  • 14
  • 25
0
votes
1 answer

How do I pass a block with other arguments?

def test(args,&block) yield end test 1, {puts "hello"} Last line doesn't work. How do I pass a block with other arguments?
Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68
0
votes
1 answer

Yield complete block in ember

I wondered how I can yield the complete block which I pass to my component. I already found this https://guides.emberjs.com/v2.9.0/components/block-params/ but I don't understand why there is //my-component.hbs {{#if hasBlock}} {{yield…
Benny Alex
  • 131
  • 2
  • 12
0
votes
0 answers

Node.js replace promise code by generators and yield

Here is this code with promises: it("#execute()", () => { let status = master.getStatus(); let filename = getTempFile("Attachment-execute.fdb"); const stmt1 = "create table t2 (n1 integer)"; const stmt2 = "create…
0
votes
1 answer

Generator that yields subpatterns of an original pattern with zeros introduced

I have the following problem in which I want to generate patterns with a 0 introduced. The problem is that this should be space efficient, and thus I would like to use a generator that creates and returns one of the patterns at a time (i.e. I do not…
0
votes
1 answer

Recursive Generator Function Python Nested JSON Data

I'm attempting to write a recursive generator function to flatten a nested json object of mixed types, lists and dictionaries. I am doing this partly for my own learning so have avoided grabbing an example from the internet to ensure I better…
Simon Tulett
  • 149
  • 1
  • 9
0
votes
1 answer

Inserting yield() into form_for() raises an error uncaught by test

I'm following the http://railstutorial.org. I finished everything up to 10.2 section excluded. Then I encountered some kind of a problem. My current application codes are below. Exercise 2 in section 7.3.4 made me add some additional code to…
AkaZecik
  • 980
  • 2
  • 11
  • 16
0
votes
2 answers

Changing the name on this Ruby class causes an error

I have the following code and it runs as it should: class Array def my_name first_name = "Bob" last_name = "Smith" yield(first_name, last_name) end end ['a', 'b', 'c', 'd'].my_name {|i, x| puts "#{i} #{x}"} But the moment I change…
John123
  • 301
  • 3
  • 19
0
votes
0 answers

Custom yield iterator return the result like Where method

public static IEnumerable Matches(this IEnumerable source, Expression> predicate, string pattern) { if (source == null) throw new ArgumentNullException("source"); Regex regex = new Regex(pattern); var…
neihmac
  • 11
  • 2
0
votes
1 answer

get the request response in Koa with koa-request in node

I'm getting started with Koa ecosystem. I know it's based in generator functions (a topic that is pretty new for me, for now), and I'm having issues with a very simple task: Call an external web service, fetch the response and send it to the client…
AlexAcc
  • 601
  • 2
  • 10
  • 28
0
votes
1 answer

Laravel Blade : Not all properties go through to certain mini-views using @yield

I am working with Laravel and created a master.blade view file to use on all my pages. The master view yields mini-views inside. On most mini-views everything works fine, but on some, I don't get the background image from the master. The problem is…
0
votes
0 answers

Coroutines with Subroutines in Visual Studio 2015

Visual Studio 2015 supports coroutines, so I can do this, for example: #include #include auto gen(int increment) { int i=1; while(true) { for(int j=0; j
user3768612
  • 101
  • 1
  • 1
  • 4
0
votes
5 answers

Ruby default block and yield

I am working on the following problem: describe "some silly block functions" do describe "reverser" do it "reverses the string returned by the default block" do result = reverser do "hello" end expect(result).to…
John
  • 229
  • 2
  • 10
0
votes
2 answers

Hybrid Generator/Function in Python

Is is possible in Python to have a generator that yields values in a loop be alternatively called as a normal function where the final value of that loop is returned? I tried setting a flag as argument and then choose to yield or return depending on…
Mehdi
  • 1,370
  • 3
  • 15
  • 26
0
votes
2 answers

python - Yield improperly usage

Im pretty sure im using yield improperly: #!/usr/bin/env python # -*- coding: utf-8 -*- import logging from gensim import corpora, models, similarities from collections import defaultdict from pprint import pprint # pretty-printer from six import…
Eran Moshe
  • 3,062
  • 2
  • 22
  • 41