Browse files

Alphabetize the methods in List

  • Loading branch information...
1 parent 7257199 commit 584be6061b6af297e4868c9ce1bdf25866ce7e66 Tony Arcieri committed Feb 12, 2011
Showing with 75 additions and 80 deletions.
  1. +75 −80 src/builtins/list.re
View
155 src/builtins/list.re
@@ -28,6 +28,36 @@ class List
replace(index, value)
end
end
+
+ # Takes a conditional block and returns true if all elements meet the
+ # condition, false otherwise
+ def all?(&block)
+ erl.lists.all(block, self)
+ end
+
+ # Takes a conditional block and returns true if any element meets the
+ # condition, false otherwise
+ def any?(&block)
+ erl.lists.any(block, self)
+ end
+
+ # Returns a new list built by concatenating the two lists together to
+ # produce a third list.
+ def append(other_list)
+ erl.lists.append(self, other_list)
+ end
+
+ # Iterate over a list, successively calling the given block and returning
+ # the receiver when done
+ def each(&block)
+ erl.lists.foreach(block, self)
+ self
+ end
+
+ # Is the list empty?
+ def empty?
+ self == []
+ end
# Returns the first element in the list
def first
@@ -38,40 +68,17 @@ class List
def first(n)
erl.lists.sublist(self, n)
end
-
- # Returns the last element in the list
- def last
- erl.lists.nth(size(), self)
- end
-
- # returns the last n-elements in the list
- def last(n)
- index = [0, (size() - n)].max()
- erl.lists.nthtail(index,self)
- end
-
- # Returns the first element of list that compares less than or equal
- # to all other elements of list.
- def min
- erl.lists.min(self)
- end
-
- # Returns the first element of list that compares greater than or equal
- # to all other elements of list.
- def max
- erl.lists.max(self)
- end
-
- # Number of elements in a list
- def size
- erl.length(self)
+
+ # Flatten a deeply nested list
+ def flatten
+ erl.lists.flatten(self)
end
- # Reverse the order of a list
- def reverse
- erl.lists.reverse(self)
+ # Generate a string representative of a list's contents
+ def inspect
+ to_s()
end
-
+
# Join a list into a string, casting all elements to strings
def join(separator)
elements = case self
@@ -87,41 +94,33 @@ class List
join("")
end
- # Returns a new list built by concatenating the two lists together to
- # produce a third list.
- def append(other_list)
- erl.lists.append(self, other_list)
- end
-
- # Iterate over a list, successively calling the given block and returning
- # the receiver when done
- def each(&block)
- erl.lists.foreach(block, self)
- self
+ # Returns the last element in the list
+ def last
+ erl.lists.nth(size(), self)
end
+ # returns the last n-elements in the list
+ def last(n)
+ index = [0, (size() - n)].max()
+ erl.lists.nthtail(index,self)
+ end
+
# Iterate over a list, building a new list of values returned from the
# given block when called with each element in the list
def map(&block)
erl.lists.map(block, self)
end
- # Takes a conditional block and returns true if all elements meet the
- # condition, false otherwise
- def all?(&block)
- erl.lists.all(block, self)
- end
-
- # Takes a conditional block and returns true if any element meets the
- # condition, false otherwise
- def any?(&block)
- erl.lists.any(block, self)
+ # Returns the first element of list that compares greater than or equal
+ # to all other elements of list.
+ def max
+ erl.lists.max(self)
end
-
- # Takes a conditional block and returns a new list with only the elements
- # for which the block evaluates to true
- def select(&block)
- erl.lists.filter(block, self)
+
+ # Returns the first element of list that compares less than or equal
+ # to all other elements of list.
+ def min
+ erl.lists.min(self)
end
# Takes a conditional block and partitions the list into two lists,
@@ -132,31 +131,32 @@ class List
erl.lists.partition(block, self)
end
- # Flatten a deeply nested list
- def flatten
- erl.lists.flatten(self)
+ # Reverse the order of a list
+ def reverse
+ erl.lists.reverse(self)
+ end
+
+ # Takes a conditional block and returns a new list with only the elements
+ # for which the block evaluates to true
+ def select(&block)
+ erl.lists.filter(block, self)
end
- # Generate a string representative of a list's contents
- def inspect
- to_s()
+ # Number of elements in a list
+ def size
+ erl.length(self)
end
- # Cast to a tuple
- def to_tuple
- erl.list_to_tuple(self)
+ # Cast to a binary
+ def to_binary
+ erl.list_to_binary(self)
end
-
+
# Cast a list of 2-tuples to a dict
def to_dict
erl.dict.from_list(self)
end
- # Cast to a binary
- def to_binary
- erl.list_to_binary(self)
- end
-
# Cast to a list, returning the identity
def to_list
self
@@ -181,14 +181,9 @@ class List
"[#{map { |e| e.inspect() }.join(',')}]"
end
- # Is the list empty?
- def empty?
- case self
- when []
- true
- when _
- false
- end
+ # Cast to a tuple
+ def to_tuple
+ erl.list_to_tuple(self)
end
# FIXME: implement private

0 comments on commit 584be60

Please sign in to comment.