Class: Prelude::ArrayList
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
#cons, #head, #null, #tail
#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)
@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
|
#length ⇒ Object
40
41
42
|
# File 'lib/prelude/array_list.rb', line 40
def length
@arr.length
end
|
#reverse ⇒ Object
48
49
50
|
# File 'lib/prelude/array_list.rb', line 48
def reverse
@arr.reverse
end
|
#to_a ⇒ Object
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
|
#transpose ⇒ Object
52
53
54
|
# File 'lib/prelude/array_list.rb', line 52
def transpose
@arr.transpose
end
|