Forum: Ruby-core [ruby-trunk - Feature #8572][Open] Fiber should be a Enumerable

1ba93fd9e39ebf48777f217c38e768fd?d=identicon&s=25 mattn (Yasuhiro Matsumoto) (Guest)
on 2013-06-28 02:16
(Received via mailing list)
Issue #8572 has been reported by mattn (Yasuhiro Matsumoto).

----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 ko1 (Koichi Sasada) (Guest)
on 2013-08-09 12:46
(Received via mailing list)
Issue #8572 has been updated by ko1 (Koichi Sasada).

Assignee set to ko1 (Koichi Sasada)

Use case?

----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41032

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
1ba93fd9e39ebf48777f217c38e768fd?d=identicon&s=25 mattn (Yasuhiro Matsumoto) (Guest)
on 2013-09-02 07:36
(Received via mailing list)
Issue #8572 has been updated by mattn (Yasuhiro Matsumoto).


=begin
ko1 (Koichi Sasada) wrote:
> Use case?

(({f = Fiber.new {
  Fiber.yield 3
  Fiber.yield 2
  Fiber.yield 1
  Fiber.yield 0
}

f.each do |x|
  puts x
end
=end
}))

For example, I want to do `each` for Fiber. But it can't
----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41524

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
054b5f6b8afdd5f6190bad08e46cd782?d=identicon&s=25 zzak (Zachary Scott) (Guest)
on 2013-09-03 07:14
(Received via mailing list)
Issue #8572 has been updated by zzak (Zachary Scott).


You could always included Enumerable in your class that implements Fiber
and define #each
----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41555

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
054b5f6b8afdd5f6190bad08e46cd782?d=identicon&s=25 zzak (Zachary Scott) (Guest)
on 2013-09-03 07:35
(Received via mailing list)
Issue #8572 has been updated by zzak (Zachary Scott).


Sorry, I missed your gist orz
----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41556

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
6789224081b49822eb70f6740beb5ed5?d=identicon&s=25 knu (Akinori MUSHA) (Guest)
on 2013-09-03 08:52
(Received via mailing list)
Issue #8572 has been updated by knu (Akinori MUSHA).


=begin

We have Generator in 1.8 and Enumerator in 1.9+ that work exactly the
same as the given example.

    # In ruby 1.8, require 'generator' and call Generator.new instead
    enum = Enumerator.new { |g|
      g.yield 3
      g.yield 2
      g.yield 1
      g.yield 0
    }

    # internal style
    enum.each do |x|
      puts x
    end

    # external style
    while enum.next?
      puts enum.next
    end

One of the reasons why Fiber was originally introduced was to
reimplement Generator of ruby 1.8 in better and faster way.  Using
Fiber as implementation technique, Generator was successfully
integrated into Enumerator in Ruby 1.9.

So, Fiber is there as a low-level API for implementing Enumerator in
the first place.  It does not make much sense to me to add a
non-primitive feature to Fiber just to make it work like Enumerator.

I think we need a real use case that would explain why Fiber should be
used that way.
=end

----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41559

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
1ba93fd9e39ebf48777f217c38e768fd?d=identicon&s=25 mattn (Yasuhiro Matsumoto) (Guest)
on 2013-09-09 10:29
(Received via mailing list)
Issue #8572 has been updated by mattn (Yasuhiro Matsumoto).


I think most of use case of using Fiber is something like getting stream
data or catching-up draining entities. Maybe we won't use Fiber for
getting limited resources. For example, If Fiber has each, I guess that
we will be possible to write twitter client elegant. :)

    f = Fiber.new {
      # getting twitter status
      loop {
        Fiber.yield tweet_status
      }
    }

    f.each do |x|
      puts "#{x.screen_name}: #{x.text}"
    end

----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41697

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Yukihiro Matsumoto) (Guest)
on 2013-09-09 10:32
(Received via mailing list)
Issue #8572 has been updated by matz (Yukihiro Matsumoto).


+1

Matz.

----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41698

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
308cbef6e86dfc49cce3b2d4cf42aedc?d=identicon&s=25 SASADA Koichi (Guest)
on 2013-09-09 10:38
(Received via mailing list)
Why you don't use Enumerator?

class TS
  attr_accessor :screen_name, :text
  def initialize
    @screen_name = "foo"
    @text = "sample"
  end
end

f = Enumerator.new {|g|
  # getting twitter status
  loop {
    g.yield TS.new
  }
}

f.each do |x|
  puts "#{x.screen_name}: #{x.text}"
end
1ba93fd9e39ebf48777f217c38e768fd?d=identicon&s=25 mattn (Yasuhiro Matsumoto) (Guest)
on 2013-09-09 13:31
(Received via mailing list)
Issue #8572 has been updated by mattn (Yasuhiro Matsumoto).


> Why you don't use Enumerator?

Ah, make sense.
----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-41700

Author: mattn (Yasuhiro Matsumoto)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 ko1 (Koichi Sasada) (Guest)
on 2013-09-30 13:26
(Received via mailing list)
Issue #8572 has been updated by ko1 (Koichi Sasada).

Category set to core
Status changed from Open to Feedback
Target version set to next minor

Can I close it?
----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-42097

Author: mattn (Yasuhiro Matsumoto)
Status: Feedback
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: next minor


I'm thinking that Fiber should be a Enumerable. it's easy and reasonable
to implement.

https://gist.github.com/mattn/5874949
1ba93fd9e39ebf48777f217c38e768fd?d=identicon&s=25 unknown (Guest)
on 2014-03-14 01:08
(Received via mailing list)
Issue #8572 has been updated by Yasuhiro Matsumoto.


Koichi Sasada wrote:
> Can I close it?

Sorry for delay. Close this please.

----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-45773

* Author: Yasuhiro Matsumoto
* Status: Feedback
* Priority: Normal
* Assignee: Koichi Sasada
* Category: core
* Target version: next minor
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2014-03-14 01:45
(Received via mailing list)
Issue #8572 has been updated by Nobuyoshi Nakada.

Status changed from Feedback to Closed

----------------------------------------
Feature #8572: Fiber should be a Enumerable
https://bugs.ruby-lang.org/issues/8572#change-45775

* Author: Yasuhiro Matsumoto
* Status: Closed
* Priority: Normal
* Assignee: Koichi Sasada
* Category: core
* Target version: next minor
This topic is locked and can not be replied to.