generator

Recursive generator in Rust causing “recursive type” error; workaround?

冷暖自知 提交于 2019-12-23 02:55:31
问题 I have a construct of the form: pub enum Value { Nil, Str(String), Seq(Vec<Value>), } A Value is either null, a string, or a vector of other Value s, which can then in turn be any of the three options. I'd like to make a method that lazily iterates over each String in a Value , respecting nesting. My first attempt looks something like this: #![feature(generators)] #![feature(generator_trait)] use std::ops::{Generator, GeneratorState}; use std::pin::Pin; fn gen_to_iter<G>(g: G) -> impl

Free/OSS Data model diagram generator from DDL

末鹿安然 提交于 2019-12-23 01:33:05
问题 I am looking for some free/oss to reverse engineer from DDL a data model diagram. My database is Oracle if that matters. Do any exist? 回答1: http://schemaspy.sourceforge.net/ 回答2: SQL Power architect has a GPL version (though it looks like they are releasing an 'Enterprise' edition soon) There is also FabForce's DBDesigner, though it is more geared to MySQL (but has some Oracle capability) 回答3: You could also look at sql-developer and data-modeler from Oracle. both are free http://www.oracle

initialValue attribute of @TableGenerator shows issue in Hibernate but not in JPA

柔情痞子 提交于 2019-12-22 18:24:04
问题 package com.sb.firstjpaexample.pojo; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.TableGenerator; @Entity @Table(name = "EMPLOYEE") public class Employee { @Id @TableGenerator(name = "TABLE_GEN", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName

multithreading: Why aren't generators thread-safe? What happens when it is shared among threads?

被刻印的时光 ゝ 提交于 2019-12-22 08:48:56
问题 I'm reading this question which asks if generators are thread-safe, and one answer said: It's not thread-safe; simultaneous calls may interleave, and mess with the local variables. Another answer shows that you can use a lock to ensure that only one thread uses the generator at a time. I'm new to multithreading. Can anyone devise an example to show what exactly happens when you use the generator without lock? For example, it doesn't seem to have any problems if I do this: import threading def

Better way than using `Task/produce/consume` for lazy collections express as coroutines

不想你离开。 提交于 2019-12-22 08:13:32
问题 It is very convenient to use Tasks to express a lazy collection / a generator. Eg: function fib() Task() do prev_prev = 0 prev = 1 produce(prev) while true cur = prev_prev + prev produce(cur) prev_prev = prev prev = cur end end end collect(take(fib(), 10)) Output: 10-element Array{Int64,1}: 1 1 2 3 5 8 13 21 34 However, they do not follow good iterator conventions at all. They are as badly behaved as they can be They do not use the returned state state start(fib()) == nothing #It has no state

is this primes generator pythonic

牧云@^-^@ 提交于 2019-12-22 07:41:03
问题 Is the following code for generating primes pythonic? def get_primes(n): primes=[False,False]+[True]*(n-1) next_p=(i for i,j in enumerate(primes) if j) while True: p=next(next_p) yield p primes[p*p::p]=[False]*((n-p*p)//p+1) Note that next(next_p) will eventually throw a StopIteration error which somehow ends the function get_primes. Is that bad? Also note that next_p is a generator which iterates over primes, however primes changes during iteration. Is that bad style? adding the following if

is this primes generator pythonic

…衆ロ難τιáo~ 提交于 2019-12-22 07:40:51
问题 Is the following code for generating primes pythonic? def get_primes(n): primes=[False,False]+[True]*(n-1) next_p=(i for i,j in enumerate(primes) if j) while True: p=next(next_p) yield p primes[p*p::p]=[False]*((n-p*p)//p+1) Note that next(next_p) will eventually throw a StopIteration error which somehow ends the function get_primes. Is that bad? Also note that next_p is a generator which iterates over primes, however primes changes during iteration. Is that bad style? adding the following if

Apply reduce on generator output with multiprocessing

牧云@^-^@ 提交于 2019-12-22 07:25:32
问题 I have a generator function (Python) that works like this def Mygenerator(x, y, z, ...): while True: # code that makes two matrices based on sequences of input arrays yield (matrix1, matrix2) What I want to do is to add the output from this generator. This line does the job: M1, M2 = reduce(lambda x, y: x[0] + y[0], x[1] + y[1], Mygenerator(x, y, z, ...)) I would like to parallelize this to speed up the computations. It is important that the outputs from Mygenerator is reduced as it is

Simpler way to run a generator function without caring about items

给你一囗甜甜゛ 提交于 2019-12-22 07:18:18
问题 I have some use cases in which I need to run generator functions without caring about the yielded items. I cannot make them non-generaor functions because in other use cases I certainly need the yielded values. I am currently using a trivial self-made function to exhaust the generators. def exhaust(generator): for _ in generator: pass I wondered, whether there is a simpler way to do that, which I'm missing? Edit Following a use case: def create_tables(fail_silently=True): """Create the

Does ES6 Tail Call Optimization Cover Generators?

时光怂恿深爱的人放手 提交于 2019-12-22 04:56:36
问题 Does ES6's support for tail call optimization cover tail calls in generators? Suppose I have this generator for integers >= 0: var nums = function* (n) { n = n || 0; yield n; yield* nums(n + 1); }; Currently, in Chrome and Firefox, it adds a stack level with each recursive call and eventually runs into a "maximum call stack size exceeded" error. Will this still occur once ES6 is fully implemented? (I know I can write the above generator iteratively and not run into the error. I'm just curious