Class: Ramda::Internal::Transducers::TakeTransducer

Inherits:
Object
  • Object
show all
Defined in:
lib/ramda/internal/transducers/take_transducer.rb

Overview

Returns a head of collection

Instance Method Summary collapse

Instance Method Details

#call(limit, reducer) ⇒ Object

limit - number



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ramda/internal/transducers/take_transducer.rb', line 7

def call(limit, reducer)
  count = 0
  lambda do |acc, x|
    count += 1
    if limit >= count
      reducer.call(acc, x)
    else
      acc
    end
  end
end