Class: Array::Seq

Inherits:
Object show all
Includes:
Apricot::Seq
Defined in:
lib/apricot/ruby_ext.rb

Instance Method Summary collapse

Methods included from Apricot::Seq

#<=>, #cons, #empty?, #hash, #last, #rest, #to_s, #to_seq

Methods included from Enumerable

#to_list

Constructor Details

#initialize(array, offset = 0) ⇒ Seq

Returns a new instance of Seq.



54
55
56
57
# File 'lib/apricot/ruby_ext.rb', line 54

def initialize(array, offset = 0)
  @array = array
  @offset = offset
end

Instance Method Details

#countObject



75
76
77
# File 'lib/apricot/ruby_ext.rb', line 75

def count
  @array.length - @offset
end

#eachObject



71
72
73
# File 'lib/apricot/ruby_ext.rb', line 71

def each
  @array[@offset..-1].each {|x| yield x }
end

#firstObject



59
60
61
# File 'lib/apricot/ruby_ext.rb', line 59

def first
  @array[@offset]
end

#nextObject



63
64
65
66
67
68
69
# File 'lib/apricot/ruby_ext.rb', line 63

def next
  if @offset + 1 < @array.length
    Seq.new(@array, @offset + 1)
  else
    nil
  end
end

#to_aObject



79
80
81
# File 'lib/apricot/ruby_ext.rb', line 79

def to_a
  @array[@offset..-1]
end