Module: Enumerable

Included in:
EnumerableFu::Filter, EnumerableFu::Merger, EnumerableFu::Zipper
Defined in:
lib/enumerable_fu/filtering.rb

Instance Method Summary collapse

Instance Method Details

#collectingObject


25
26
27
28
29
30
31
# File 'lib/enumerable_fu/filtering.rb', line 25

def collecting
  EnumerableFu::Filter.new do |output|
    each do |element|
      output.call yield(element)
    end
  end
end

#rejectingObject


41
42
43
44
45
46
47
# File 'lib/enumerable_fu/filtering.rb', line 41

def rejecting
  EnumerableFu::Filter.new do |output|
    each do |element|
      output.call(element) unless yield(element)
    end
  end
end

#selectingObject


33
34
35
36
37
38
39
# File 'lib/enumerable_fu/filtering.rb', line 33

def selecting
  EnumerableFu::Filter.new do |output|
    each do |element|
      output.call(element) if yield(element)
    end
  end
end

#uniqingObject


49
50
51
52
53
54
55
56
# File 'lib/enumerable_fu/filtering.rb', line 49

def uniqing
  EnumerableFu::Filter.new do |output|
    seen = Set.new
    each do |element|
      output.call(element) if seen.add?(element)
    end
  end
end

#uniqing_byObject


58
59
60
61
62
63
64
65
# File 'lib/enumerable_fu/filtering.rb', line 58

def uniqing_by
  EnumerableFu::Filter.new do |output|
    seen = Set.new
    each do |element|
      output.call(element) if seen.add?(yield element)
    end
  end
end