Module: Elixir::Enum
- Defined in:
- lib/elixir/enum.rb
Class Method Summary collapse
- .all?(collection, &block) ⇒ Boolean
- .any?(collection, &block) ⇒ Boolean
- .at(collection, index, default = nil) ⇒ Object
- .chunk(collection, n, step: nil, pad: nil) ⇒ Object
- .chunk_by(collection, &block) ⇒ Object
- .concat(*collections) ⇒ Object
- .count(collection, &block) ⇒ Object
- .drop(collection, count) ⇒ Object
- .drop_while(collection, &block) ⇒ Object
- .each(collection, &block) ⇒ Object
- .empty?(collection) ⇒ Boolean
- .fetch(collection, n) ⇒ Object
- .fetch!(collection, n) ⇒ Object
- .filter(collection, &block) ⇒ Object
- .filter_map(collection, filter, mapper) ⇒ Object
- .find(collection, ifnone = nil, &block) ⇒ Object
- .find_index(collection, &block) ⇒ Object
- .find_value(collection, ifnone = nil, &block) ⇒ Object
- .flat_map(collection, &block) ⇒ Object
- .flat_map_reduce(collection, acc, &block) ⇒ Object
- .group_by(collection, &block) ⇒ Object
- .intersperse(collection, element) ⇒ Object
- .into(collection, list, transform = nil) ⇒ Object
- .join(collection, joiner = '') ⇒ Object
- .map(collection, &block) ⇒ Object
- .map_join(collection, joiner = '', &block) ⇒ Object
- .map_reduce(collection, acc, &block) ⇒ Object
- .max(collection) ⇒ Object
- .max_by(collection, &block) ⇒ Object
- .member?(collection, value) ⇒ Boolean
- .min(collection) ⇒ Object
- .min_by(collection, &block) ⇒ Object
- .partition(collection, &block) ⇒ Object
- .reduce(collection, acc = nil, &block) ⇒ Object
- .reject(collection, &block) ⇒ Object
- .reverse(collection, tail = nil) ⇒ Object
- .scan(collection, acc = 0, &block) ⇒ Object
- .shuffle(collection) ⇒ Object
- .slice(collection, x, count = nil) ⇒ Object
- .sort(collection, &block) ⇒ Object
- .sort_by(collection, mapper, sorter = nil) ⇒ Object
- .split(collection, count) ⇒ Object
- .split_while(collection, &block) ⇒ Object
- .sum(collection) ⇒ Object
- .take(collection, count) ⇒ Object
- .take_every(collection, nth) ⇒ Object
- .take_while(collection, &block) ⇒ Object
- .to_list(collection) ⇒ Object
- .uniq(collection, &block) ⇒ Object
- .with_index(collection) ⇒ Object
- .zip(collection1, collection2) ⇒ Object
Class Method Details
.all?(collection, &block) ⇒ Boolean
5 6 7 |
# File 'lib/elixir/enum.rb', line 5 def all? collection, &block collection.all? &block end |
.any?(collection, &block) ⇒ Boolean
9 10 11 |
# File 'lib/elixir/enum.rb', line 9 def any? collection, &block collection.any? &block end |
.at(collection, index, default = nil) ⇒ Object
13 14 15 |
# File 'lib/elixir/enum.rb', line 13 def at collection, index, default = nil collection.first(index.next)[index] || default end |
.chunk(collection, n, step: nil, pad: nil) ⇒ Object
17 18 19 |
# File 'lib/elixir/enum.rb', line 17 def chunk collection, n, step: nil, pad: nil # TODO end |
.chunk_by(collection, &block) ⇒ Object
21 22 23 |
# File 'lib/elixir/enum.rb', line 21 def chunk_by collection, &block collection.chunk(&block).map(&:last).to_a end |
.concat(*collections) ⇒ Object
25 26 27 |
# File 'lib/elixir/enum.rb', line 25 def concat *collections collections.inject :concat end |
.count(collection, &block) ⇒ Object
29 30 31 |
# File 'lib/elixir/enum.rb', line 29 def count collection, &block collection.count &block end |
.drop(collection, count) ⇒ Object
33 34 35 |
# File 'lib/elixir/enum.rb', line 33 def drop collection, count collection.drop count end |
.drop_while(collection, &block) ⇒ Object
37 38 39 |
# File 'lib/elixir/enum.rb', line 37 def drop_while collection, &block collection.drop_while &block end |
.each(collection, &block) ⇒ Object
41 42 43 44 45 |
# File 'lib/elixir/enum.rb', line 41 def each collection, &block collection.each &block :ok end |
.empty?(collection) ⇒ Boolean
47 48 49 |
# File 'lib/elixir/enum.rb', line 47 def empty? collection collection.empty? end |
.fetch(collection, n) ⇒ Object
51 52 53 |
# File 'lib/elixir/enum.rb', line 51 def fetch collection, n # TODO end |
.fetch!(collection, n) ⇒ Object
55 56 57 |
# File 'lib/elixir/enum.rb', line 55 def fetch! collection, n # TODO end |
.filter(collection, &block) ⇒ Object
59 60 61 |
# File 'lib/elixir/enum.rb', line 59 def filter collection, &block collection.select &block end |
.filter_map(collection, filter, mapper) ⇒ Object
63 64 65 |
# File 'lib/elixir/enum.rb', line 63 def filter_map collection, filter, mapper # TODO end |
.find(collection, ifnone = nil, &block) ⇒ Object
67 68 69 |
# File 'lib/elixir/enum.rb', line 67 def find collection, ifnone = nil, &block collection.find ifnone, &block end |
.find_index(collection, &block) ⇒ Object
71 72 73 |
# File 'lib/elixir/enum.rb', line 71 def find_index collection, &block # TODO end |
.find_value(collection, ifnone = nil, &block) ⇒ Object
75 76 77 |
# File 'lib/elixir/enum.rb', line 75 def find_value collection, ifnone = nil, &block # TODO end |
.flat_map(collection, &block) ⇒ Object
79 80 81 |
# File 'lib/elixir/enum.rb', line 79 def flat_map collection, &block collection.flat_map &block end |
.flat_map_reduce(collection, acc, &block) ⇒ Object
83 84 85 |
# File 'lib/elixir/enum.rb', line 83 def flat_map_reduce collection, acc, &block # TODO end |
.group_by(collection, &block) ⇒ Object
87 88 89 |
# File 'lib/elixir/enum.rb', line 87 def group_by collection, &block collection.group_by(&block).map { |k, v| [k.to_s.to_sym, v] }.to_h end |
.intersperse(collection, element) ⇒ Object
91 92 93 |
# File 'lib/elixir/enum.rb', line 91 def intersperse collection, element collection.each_with_object(element).to_a.flatten 1 end |
.into(collection, list, transform = nil) ⇒ Object
95 96 97 |
# File 'lib/elixir/enum.rb', line 95 def into collection, list, transform = nil # TODO end |
.join(collection, joiner = '') ⇒ Object
99 100 101 |
# File 'lib/elixir/enum.rb', line 99 def join collection, joiner = '' collection.join joiner end |
.map(collection, &block) ⇒ Object
103 104 105 |
# File 'lib/elixir/enum.rb', line 103 def map collection, &block collection.map &block end |
.map_join(collection, joiner = '', &block) ⇒ Object
107 108 109 |
# File 'lib/elixir/enum.rb', line 107 def map_join collection, joiner = '', &block collection.map(&block).join joiner end |
.map_reduce(collection, acc, &block) ⇒ Object
111 112 113 |
# File 'lib/elixir/enum.rb', line 111 def map_reduce collection, acc, &block # TODO end |
.max(collection) ⇒ Object
115 116 117 |
# File 'lib/elixir/enum.rb', line 115 def max collection collection.max or raise 'empty error' end |
.max_by(collection, &block) ⇒ Object
119 120 121 |
# File 'lib/elixir/enum.rb', line 119 def max_by collection, &block collection.max_by &block end |
.member?(collection, value) ⇒ Boolean
123 124 125 |
# File 'lib/elixir/enum.rb', line 123 def member? collection, value collection.member? value end |
.min(collection) ⇒ Object
127 128 129 |
# File 'lib/elixir/enum.rb', line 127 def min collection collection.min or raise 'empty error' end |
.min_by(collection, &block) ⇒ Object
131 132 133 |
# File 'lib/elixir/enum.rb', line 131 def min_by collection, &block collection.min_by &block end |
.partition(collection, &block) ⇒ Object
135 136 137 |
# File 'lib/elixir/enum.rb', line 135 def partition collection, &block collection.partition &block end |
.reduce(collection, acc = nil, &block) ⇒ Object
139 140 141 |
# File 'lib/elixir/enum.rb', line 139 def reduce collection, acc = nil, &block collection.reduce acc, &block end |
.reject(collection, &block) ⇒ Object
143 144 145 |
# File 'lib/elixir/enum.rb', line 143 def reject collection, &block collection.reject &block end |
.reverse(collection, tail = nil) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/elixir/enum.rb', line 147 def reverse collection, tail = nil if tail collection.reverse << tail else collection.reverse end end |
.scan(collection, acc = 0, &block) ⇒ Object
155 156 157 |
# File 'lib/elixir/enum.rb', line 155 def scan collection, acc = 0, &block # TODO end |
.shuffle(collection) ⇒ Object
159 160 161 |
# File 'lib/elixir/enum.rb', line 159 def shuffle collection collection.shuffle end |
.slice(collection, x, count = nil) ⇒ Object
163 164 165 |
# File 'lib/elixir/enum.rb', line 163 def slice collection, x, count = nil # TODO end |
.sort(collection, &block) ⇒ Object
167 168 169 |
# File 'lib/elixir/enum.rb', line 167 def sort collection, &block collection.sort &block end |
.sort_by(collection, mapper, sorter = nil) ⇒ Object
171 172 173 |
# File 'lib/elixir/enum.rb', line 171 def sort_by collection, mapper, sorter = nil # TODO end |
.split(collection, count) ⇒ Object
175 176 177 |
# File 'lib/elixir/enum.rb', line 175 def split collection, count # TODO end |
.split_while(collection, &block) ⇒ Object
179 180 181 |
# File 'lib/elixir/enum.rb', line 179 def split_while collection, &block # TODO end |
.sum(collection) ⇒ Object
183 184 185 |
# File 'lib/elixir/enum.rb', line 183 def sum collection collection.inject :+ end |
.take(collection, count) ⇒ Object
187 188 189 |
# File 'lib/elixir/enum.rb', line 187 def take collection, count collection.take count end |
.take_every(collection, nth) ⇒ Object
191 192 193 |
# File 'lib/elixir/enum.rb', line 191 def take_every collection, nth collection.each_slice(nth).map &:first end |
.take_while(collection, &block) ⇒ Object
195 196 197 |
# File 'lib/elixir/enum.rb', line 195 def take_while collection, &block # TODO end |
.to_list(collection) ⇒ Object
199 200 201 |
# File 'lib/elixir/enum.rb', line 199 def to_list collection collection.to_a end |
.uniq(collection, &block) ⇒ Object
203 204 205 |
# File 'lib/elixir/enum.rb', line 203 def uniq collection, &block collection.uniq &block end |
.with_index(collection) ⇒ Object
207 208 209 |
# File 'lib/elixir/enum.rb', line 207 def with_index collection collection.each_with_index.to_a end |
.zip(collection1, collection2) ⇒ Object
211 212 213 |
# File 'lib/elixir/enum.rb', line 211 def zip collection1, collection2 collection1.zip collection2 end |