Module: Enumerable

Defined in:
lib/kleene/patches.rb

Instance Method Summary collapse

Instance Method Details

#compact_map(&block) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/kleene/patches.rb', line 11

def compact_map(&block)
  ary = []
  each do |e|
    v = block.call(e)
    ary << v unless v.nil?
  end
  ary
end

#find_map(&block) ⇒ Object

calls the block with successive elements; returns the first truthy object returned by the block



3
4
5
6
7
8
9
# File 'lib/kleene/patches.rb', line 3

def find_map(&block)
  each do |element|
    mapped_value = block.call(element)
    return mapped_value if mapped_value
  end
  nil
end