Class: Functional::Cons

Inherits:
Base show all
Defined in:
lib/functional.rb

Instance Attribute Summary

Attributes inherited from Base

#caller, #exe, #next

Instance Method Summary collapse

Methods inherited from Base

#base_fun, #clean, #to_proc

Constructor Details

#initialize(n) ⇒ Cons

Returns a new instance of Cons.



279
280
281
# File 'lib/functional.rb', line 279

def initialize n
  @buf, @n = [], n
end

Instance Method Details

#cons_fun(*a) ⇒ Object Also known as: call



283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/functional.rb', line 283

def cons_fun *a
  @buf.push a
  unless @n > @buf.size
    class <<self
      def call *a
        @buf.push a
        @next.call @buf
        @buf.shift
      end
    end
    @next.call @buf
    @buf.shift
  end
end

#endObject



299
300
301
302
# File 'lib/functional.rb', line 299

def end
  @next.call @buf  unless @n > @buf.size
  @next.end
end