Questions tagged as 'generators'

1
answer

What are the advantages of using a Generator (yield) in PHP?

Since PHP 5.5 was implemented in the Generator language. It can be used inside a function from the keyword yield . In the Manual , we have an example where one is compared to the function range(0, 1000000) (which theoretically...
asked by 10.02.2015 / 18:27
1
answer

Difference between yield and yield * operators in ECMAScript 6.0 "Harmony"?

I'm studying the use of generators in ECMAScript 6.0 "Harmony" . I have already been able to understand its basic operation, such as declaration through the function* () { ... } syntax and the production of values through the yie...
asked by 11.12.2013 / 20:01
1
answer

With an iterator / generator in javascript?

In PHP we have the Iterators and the Generator . Example Iterator: $f = new FileSystemIterator(__DIR__); foreach($f as $file) { echo $file->getFilename(); } Example Generator: function sequence($start, $end) {...
asked by 08.10.2015 / 17:06
2
answers

How to "simulate" a Generator in versions prior to PHP 5.5?

As of PHP 5.5 we can use yield instead of return in functions and, with that, we create Generators . The reasons for using yield can be seen here What are the advantages of using a Generator (yield) in PHP? But...
asked by 01.09.2015 / 17:42
1
answer

Generating functions: What are the advantages of using them?

Generating function: def geraQuadrados(n): for i in range(n): yield i**2 for i in geraQuadrados(5): print(i) No generating function: def novosQuadrados(n): l = [] for i in range(n): l.app...
asked by 05.04.2018 / 14:17
2
answers

generator

Well, I've been trying to optimize my code and found generator expressions, but I do not understand anything about it. For example: for mCp in mWithoutNone: for ctt in moradasCTT: if mCp[3] == ctt[3]: mWithCp4.append...
asked by 05.07.2017 / 13:49
2
answers

model and controller in codeigniter to do insert in firebird using generator

I'm new to codeigniter and I need to define my controller and model, so when calling the model inserir() , the controller takes the last ID of the generator of each table that wants to do the insert. Let me give you an example: control...
asked by 13.01.2016 / 14:24
1
answer

Stop generator

What would be the best way to stop a generator? Example: >>> def get_fruits(): fruits = ['Mamão', 'Abacate', 'Melão', 'Banana', 'Maçã', 'Uva'] for fruit in fruits: yield fruit >>> my_bag = [] &g...
asked by 12.02.2016 / 00:44
1
answer

How to generate sequential numbers automatically with current year in rails?

I need when a new product is created it generates a number ex: 0001/2015 number / year_vigente and when change of year returns to zero. I made a helper just to format the number in the views, but it does not solve the problem of automatic gen...
asked by 15.05.2015 / 21:26