Module: Enumerable

Included in:
OpenObject
Defined in:
lib/lab42/core/enumerable.rb,
lib/lab42/core/console_tools/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#find_with_value(default_value = nil, &blk) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/lab42/core/enumerable.rb', line 3

def find_with_value default_value=nil, &blk
  each do | val |
    val_prime = blk.(val)
    return val_prime if val_prime
  end
  default_value
end

#grep2(expr) ⇒ Object



11
12
13
# File 'lib/lab42/core/enumerable.rb', line 11

def grep2 expr
  partition{ |ele| expr === ele }
end

#mm(*args) ⇒ Object



3
4
5
# File 'lib/lab42/core/console_tools/enumerable.rb', line 3

def mm *args
  map &B(*args)
end

#to_procObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lab42/core/enumerable.rb', line 16

def to_proc
  this = self
  yielder = to_enum.lazy
  -> do
    yielder.next
  end
    .extend( Module.new do
      define_method :reset! do
        yielder = this.to_enum.lazy
      end
    end)
end