Module: Elixir::List
- Defined in:
- lib/elixir/list.rb
Class Method Summary collapse
- .delete(array, item) ⇒ Object
- .delete_at(array, index) ⇒ Object
- .duplicate(elem, n) ⇒ Object
- .first(array) ⇒ Object
- .flatten(array, tail = []) ⇒ Object
- .foldl(array, acc, &fun) ⇒ Object
- .foldr(array, acc, &fun) ⇒ Object
- .insert_at(array, index, value) ⇒ Object
- .keydelete(array, key, position) ⇒ Object
- .keyfind(array, key, position, default = nil) ⇒ Object
- .keymember?(array, key, position) ⇒ Boolean
- .keyreplace(array, key, position, new_array) ⇒ Object
- .keysort(array, position) ⇒ Object
- .last(array) ⇒ Object
- .replace_at(array, index, value) ⇒ Object
- .to_atom(char_array) ⇒ Object
- .to_existing_atom(char_array) ⇒ Object
- .to_float(char_array) ⇒ Object
- .to_integer(char_array) ⇒ Object
- .to_string(array) ⇒ Object
- .to_tuple(array) ⇒ Object
- .update_at(array, index, &fun) ⇒ Object
- .wrap(obj) ⇒ Object
- .zip(array_of_arrays) ⇒ Object
Class Method Details
.delete(array, item) ⇒ Object
5 6 7 8 9 |
# File 'lib/elixir/list.rb', line 5 def delete array, item array.delete item array end |
.delete_at(array, index) ⇒ Object
11 12 13 14 15 |
# File 'lib/elixir/list.rb', line 11 def delete_at array, index array.delete_at index array end |
.duplicate(elem, n) ⇒ Object
17 18 19 |
# File 'lib/elixir/list.rb', line 17 def duplicate elem, n Array.new n, elem end |
.first(array) ⇒ Object
21 22 23 |
# File 'lib/elixir/list.rb', line 21 def first array array.first end |
.flatten(array, tail = []) ⇒ Object
25 26 27 |
# File 'lib/elixir/list.rb', line 25 def flatten array, tail = [] array.flatten + tail end |
.foldl(array, acc, &fun) ⇒ Object
29 30 31 32 33 |
# 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) ⇒ Object
35 36 37 38 39 |
# 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) ⇒ Object
41 42 43 |
# File 'lib/elixir/list.rb', line 41 def insert_at array, index, value array.insert index, value end |
.keydelete(array, key, position) ⇒ Object
45 46 47 |
# File 'lib/elixir/list.rb', line 45 def keydelete array, key, position # TODO end |
.keyfind(array, key, position, default = nil) ⇒ Object
49 50 51 |
# File 'lib/elixir/list.rb', line 49 def keyfind array, key, position, default = nil # TODO end |
.keymember?(array, key, position) ⇒ Boolean
53 54 55 |
# File 'lib/elixir/list.rb', line 53 def keymember? array, key, position # TODO end |
.keyreplace(array, key, position, new_array) ⇒ Object
57 58 59 |
# File 'lib/elixir/list.rb', line 57 def keyreplace array, key, position, new_array # TODO end |
.keysort(array, position) ⇒ Object
61 62 63 |
# File 'lib/elixir/list.rb', line 61 def keysort array, position # TODO end |
.last(array) ⇒ Object
65 66 67 |
# File 'lib/elixir/list.rb', line 65 def last array array.last end |
.replace_at(array, index, value) ⇒ Object
69 70 71 |
# File 'lib/elixir/list.rb', line 69 def replace_at array, index, value # TODO end |
.to_atom(char_array) ⇒ Object
73 74 75 |
# File 'lib/elixir/list.rb', line 73 def to_atom char_array # TODO end |
.to_existing_atom(char_array) ⇒ Object
77 78 79 |
# File 'lib/elixir/list.rb', line 77 def to_existing_atom char_array # TODO end |
.to_float(char_array) ⇒ Object
81 82 83 |
# File 'lib/elixir/list.rb', line 81 def to_float char_array # TODO end |
.to_integer(char_array) ⇒ Object
85 86 87 |
# File 'lib/elixir/list.rb', line 85 def to_integer char_array # TODO end |
.to_string(array) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# 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) ⇒ Object
102 103 104 |
# File 'lib/elixir/list.rb', line 102 def to_tuple array array end |
.update_at(array, index, &fun) ⇒ Object
106 107 108 |
# File 'lib/elixir/list.rb', line 106 def update_at array, index, &fun # TODO end |
.wrap(obj) ⇒ Object
110 111 112 |
# File 'lib/elixir/list.rb', line 110 def wrap obj obj.respond_to?(:to_a) ? obj.to_a : [obj] end |
.zip(array_of_arrays) ⇒ Object
114 115 116 117 118 119 |
# 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 |