Method: Core#reduce

Defined in:
lib/fubby/core.rb

#reduceObject

reduce

a, (b -> a), [b] -> a



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fubby/core.rb', line 25

def reduce
  curry.(->(memo, f, array) {
    if memo == nil
      case array.length
      when 0 then nil
      when 1 then array[0]
      else reduce.(f.(array[0], array[1]), f, array[2..-1])
      end
    else
      case array.length
      when 0 then memo
      else reduce.(f.(memo, array[0]), f, array[1..-1])
      end
    end
  })
end