enumerators

What are the pros and cons of Enumerators vs. Conduits vs. Pipes?

我的梦境 提交于 2020-01-09 12:18:08
问题 I'd like to hear from someone with a deeper understanding than myself what the fundamental differences are between Enumerators, Conduits, and Pipes as well as the key benefits and drawbacks. Some discussion's already ongoing but it'd be nice to have a high-level overview. 回答1: Enumerators/Iteratees as an abstraction were invented by Oleg Kiselyov. They provide a clean way of doing IO with predictable (low) resource requirements. The current Enumerators package is pretty close to Oleg's

What are the pros and cons of Enumerators vs. Conduits vs. Pipes?

夙愿已清 提交于 2020-01-09 12:17:50
问题 I'd like to hear from someone with a deeper understanding than myself what the fundamental differences are between Enumerators, Conduits, and Pipes as well as the key benefits and drawbacks. Some discussion's already ongoing but it'd be nice to have a high-level overview. 回答1: Enumerators/Iteratees as an abstraction were invented by Oleg Kiselyov. They provide a clean way of doing IO with predictable (low) resource requirements. The current Enumerators package is pretty close to Oleg's

How do Enumerators work in Ruby 1.9.1?

允我心安 提交于 2019-12-20 21:00:16
问题 This question is not about how to use Enumerators in Ruby 1.9.1 but rather I am curious how they work. Here is some code: class Bunk def initialize @h = [*1..100] end def each if !block_given? enum_for(:each) else 0.upto(@h.length) { |i| yield @h[i] } end end end In the above code I can use e = Bunk.new.each , and then e.next , e.next to get each successive element, but how exactly is it suspending execution and then resuming at the right spot? I am aware that if the yield in the 0.upto is

Concurrency or Performance Benefits of yield return over returning a list

折月煮酒 提交于 2019-12-04 15:57:03
问题 I was wondering if there is any concurrency (now or future), or performance benefit to using yield return over returning a list. See the following examples Processing Method void Page_Load() { foreach(var item in GetPostedItems()) Process(item); } using yield return IEnumerable<string> GetPostedItems() { yield return Item1.Text; yield return Item2.Text; yield return Item3.Text; } returning a list IEnumerable<string> GetPostedItems() { var list = new List<string>(); list.Add(Item1.Text); list

Concurrency or Performance Benefits of yield return over returning a list

99封情书 提交于 2019-12-03 09:55:31
I was wondering if there is any concurrency (now or future), or performance benefit to using yield return over returning a list. See the following examples Processing Method void Page_Load() { foreach(var item in GetPostedItems()) Process(item); } using yield return IEnumerable<string> GetPostedItems() { yield return Item1.Text; yield return Item2.Text; yield return Item3.Text; } returning a list IEnumerable<string> GetPostedItems() { var list = new List<string>(); list.Add(Item1.Text); list.Add(Item2.Text); list.Add(Item3.Text); return list; } In the yield return example, the result is

How do Enumerators work in Ruby 1.9.1?

人盡茶涼 提交于 2019-12-03 07:04:18
This question is not about how to use Enumerators in Ruby 1.9.1 but rather I am curious how they work. Here is some code: class Bunk def initialize @h = [*1..100] end def each if !block_given? enum_for(:each) else 0.upto(@h.length) { |i| yield @h[i] } end end end In the above code I can use e = Bunk.new.each , and then e.next , e.next to get each successive element, but how exactly is it suspending execution and then resuming at the right spot? I am aware that if the yield in the 0.upto is replaced with Fiber.yield then it's easy to understand, but that is not the case here. It is a plain old

Why does enumerating through a collection throw an exception but looping through its items does not

荒凉一梦 提交于 2019-12-01 19:34:56
问题 I was testing out some synchronization constructs and I noticed something that confused me. When I was enumerating through a collection while writing to it at the same time, it threw an exception (this was expected), but when I looped through the collection using a for loop, it did not. Can someone explain this? I thought that a List does not allow a reader and writer to operate at the same time. I would have expected looping through the collection to exhibit the same behavior as using an

What are the pros and cons of Enumerators vs. Conduits vs. Pipes?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 16:06:05
I'd like to hear from someone with a deeper understanding than myself what the fundamental differences are between Enumerators , Conduits , and Pipes as well as the key benefits and drawbacks. Some discussion's already ongoing but it'd be nice to have a high-level overview. Philip JF Enumerators/Iteratees as an abstraction were invented by Oleg Kiselyov. They provide a clean way of doing IO with predictable (low) resource requirements. The current Enumerators package is pretty close to Oleg's original work. Conduits were created for the Yesod web framework. My understanding is that they were