|
1 |
| -if RUBY_VERSION < '1.9' |
2 |
| - |
3 |
| - require 'enumerator' |
4 |
| - |
5 |
| - # for Ruby 1.8 -> 1.9 transition |
6 |
| - Enumerator = Enumerable::Enumerator unless defined?(::Enumerator) |
7 |
| - |
8 |
| - class Enumerator |
9 |
| - |
10 |
| - private |
11 |
| - |
12 |
| - alias :old_initialize :initialize |
13 |
| - |
14 |
| - # Provides the ruby-1.9 block form of Enumerator, where you can write: |
15 |
| - # |
16 |
| - # obj = Enumerator.new do |yielder| |
17 |
| - # # ... |
18 |
| - # yielder.yield(data) # or: yielder << data |
19 |
| - # # ... |
20 |
| - # end |
21 |
| - # |
22 |
| - # When obj.each is called, the block is run once. It should call |
23 |
| - # yielder.yield with each item it wishes to generate. |
24 |
| - # |
25 |
| - # Example: |
26 |
| - # |
27 |
| - # fib = Enumerator.new { |y| |
28 |
| - # a = b = 1 |
29 |
| - # loop { |
30 |
| - # y << a |
31 |
| - # a, b = b, a + b |
32 |
| - # } |
33 |
| - # } |
34 |
| - # |
35 |
| - # fib.take(10) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] |
36 |
| - # |
37 |
| - def initialize(*args, &block) |
38 |
| - if block |
39 |
| - @body = block |
40 |
| - old_initialize(self, :_start) |
41 |
| - else |
42 |
| - old_initialize(*args) |
43 |
| - end |
44 |
| - end |
45 |
| - |
46 |
| - def _start(*args,&receiver) #:nodoc: |
47 |
| - @body.call(Yielder.new(&receiver), *args) |
48 |
| - end |
49 |
| - |
50 |
| - # Wrapper to allow yielder.yield(output) or yielder << output |
51 |
| - # in the same way as ruby-1.9 |
52 |
| - # |
53 |
| - # TODO: Why can't Yielder take a block instead of a proc argument? |
54 |
| - |
55 |
| - class Yielder #:nodoc: |
56 |
| - def initialize(&proc) |
57 |
| - @proc = proc |
58 |
| - end |
59 |
| - def yield(*args) |
60 |
| - @proc[*args] |
61 |
| - end |
62 |
| - alias :<< :yield |
63 |
| - end |
64 |
| - |
65 |
| - end |
66 |
| - |
67 |
| -end |
68 |
| - |
69 |
| -path = __FILE__.chomp('.rb') |
70 |
| -base = File.basename(path) |
71 |
| -Dir[File.join(path, '*.rb')].each do |lib| |
72 |
| - #require lib # why is this so much slower? |
73 |
| - require "facets/#{base}/#{File.basename(lib)}" |
74 |
| -end |
75 |
| - |
| 1 | +require_relative 'enumerator/fx' |
| 2 | +require_relative 'enumerator/lazy/squeeze' |
0 commit comments