module Elixir::List

Public Instance Methods

delete(array, item) click to toggle source
# File lib/elixir/list.rb, line 5
def delete array, item
  array.delete item

  array
end
delete_at(array, index) click to toggle source
# File lib/elixir/list.rb, line 11
def delete_at array, index
  array.delete_at index

  array
end
duplicate(elem, n) click to toggle source
# File lib/elixir/list.rb, line 17
def duplicate elem, n
  Array.new n, elem
end
first(array) click to toggle source
# File lib/elixir/list.rb, line 21
def first array
  array.first
end
flatten(array, tail = []) click to toggle source
# File lib/elixir/list.rb, line 25
def flatten array, tail = []
  array.flatten + tail
end
foldl(array, acc, &fun) click to toggle source
# File lib/elixir/list.rb, line 29
def foldl array, acc, &fun
  array.reduce acc do |accumulator, item|
    fun.call item, accumulator
  end
end
foldr(array, acc, &fun) click to toggle source
# File lib/elixir/list.rb, line 35
def foldr array, acc, &fun
  array.reverse_each.reduce acc do |accumulator, item|
    fun.call item, accumulator
  end
end
insert_at(array, index, value) click to toggle source
# File lib/elixir/list.rb, line 41
def insert_at array, index, value
  array.insert index, value
end
keydelete(array, key, position) click to toggle source
# File lib/elixir/list.rb, line 45
def keydelete array, key, position
  # TODO
end
keyfind(array, key, position, default = nil) click to toggle source
# File lib/elixir/list.rb, line 49
def keyfind array, key, position, default = nil
  # TODO
end
keymember?(array, key, position) click to toggle source
# File lib/elixir/list.rb, line 53
def keymember? array, key, position
  # TODO
end
keyreplace(array, key, position, new_array) click to toggle source
# File lib/elixir/list.rb, line 57
def keyreplace array, key, position, new_array
  # TODO
end
keysort(array, position) click to toggle source
# File lib/elixir/list.rb, line 61
def keysort array, position
  # TODO
end
last(array) click to toggle source
# File lib/elixir/list.rb, line 65
def last array
  array.last
end
replace_at(array, index, value) click to toggle source
# File lib/elixir/list.rb, line 69
def replace_at array, index, value
  # TODO
end
to_atom(char_array) click to toggle source
# File lib/elixir/list.rb, line 73
def to_atom char_array
  # TODO
end
to_existing_atom(char_array) click to toggle source
# File lib/elixir/list.rb, line 77
def to_existing_atom char_array
  # TODO
end
to_float(char_array) click to toggle source
# File lib/elixir/list.rb, line 81
def to_float char_array
  # TODO
end
to_integer(char_array) click to toggle source
# File lib/elixir/list.rb, line 85
def to_integer char_array
  # TODO
end
to_string(array) click to toggle source
# File lib/elixir/list.rb, line 89
def to_string array
  array.flatten.map do |elem|
    case elem
    when ::Integer
      elem.chr
    when ::String
      elem
    else
      raise ArgumentError
    end
  end.join
end
to_tuple(array) click to toggle source
# File lib/elixir/list.rb, line 102
def to_tuple array
  array
end
update_at(array, index, &fun) click to toggle source
# File lib/elixir/list.rb, line 106
def update_at array, index, &fun
  # TODO
end
wrap(obj) click to toggle source
# File lib/elixir/list.rb, line 110
def wrap obj
  obj.respond_to?(:to_a) ? obj.to_a : [obj]
end
zip(array_of_arrays) click to toggle source
# File lib/elixir/list.rb, line 114
def zip array_of_arrays
  array_of_arrays.transpose
rescue IndexError
  min_size = array_of_arrays.min_by(&:size).size
  array_of_arrays.map { |array| array.first min_size }.transpose
end