Class: Prelude::ArrayList

Inherits:
MinimalArrayList show all
Defined in:
lib/prelude/array_list.rb

Overview

$Id: array_list.rb 34 2007-10-23 21:38:09Z prelude $

Implemenation of the minimal list functionality based on Ruby’s arrays

Instance Method Summary collapse

Methods inherited from MinimalArrayList

#cons, #head, #null, #tail

Methods included from ProperRubyList

#each

Methods included from ProperList

#cons, #head, #null, #tail

Constructor Details

#initialize(a = nil) ⇒ ArrayList

Returns a new instance of ArrayList.



33
34
35
36
37
38
# File 'lib/prelude/array_list.rb', line 33

def initialize(a=nil)
  #p "new #{a.inspect}"
  @arr = []
  a.each { |e| @arr << (e.kind_of?(Array) ? ArrayList.new(e) : e) } if a
  self
end

Instance Method Details

#append(list) ⇒ Object



44
45
46
# File 'lib/prelude/array_list.rb', line 44

def append(list)
  ArrayList.new(@arr+[*list])
end

#lengthObject



40
41
42
# File 'lib/prelude/array_list.rb', line 40

def length
  @arr.length
end

#reverseObject



48
49
50
# File 'lib/prelude/array_list.rb', line 48

def reverse
  @arr.reverse
end

#to_aObject



56
57
58
59
60
# File 'lib/prelude/array_list.rb', line 56

def to_a
  res = []
  @arr.each { |e| res << (e.kind_of?(ArrayList) ? e.to_a : e) }
  res
end

#transposeObject



52
53
54
# File 'lib/prelude/array_list.rb', line 52

def transpose
  @arr.transpose
end