Elixir Enum Functions Flashcards

(77 cards)

1
Q

Returns a map with keys as unique elements of enumerable and values as the count of every element.

A

frequencies(enumerable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Returns true if fun.(element) is truthy for all elements in enumerable.

A

all?(enumerable, fun \ fn x -> x end)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Returns true if fun.(element) is truthy for at least one element in enumerable.

A

any?(enumerable, fun \ fn x -> x end)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Finds the element at the given index (zero-based).

A

at(t(), index(), default()) :: element() | default()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Splits enumerable on every element for which fun returns a new value.

A

chunk_by(enumerable, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Shortcut to chunk_every(enumerable, count, count).

A

chunk_every(enumerable, count)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Returns list of lists containing count elements each, where each new chunk starts step elements into the enumerable.

A

chunk_every(enumerable, count, step, leftover \ [])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Chunks the enumerable with fine grained control when every chunk is emitted.

A

chunk_while(enumerable, acc, chunk_fun, after_fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Turn a list of lists into a single list

A

concat(enumerables)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Concatenates the enumerable on the right with the enumerable on the left.

A

concat(left, right)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Returns the size of the enumerable.

A

count(enumerable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Returns the count of elements in the enumerable for which fun returns a truthy value.

A

count(enumerable, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Enumerates the enumerable, returning a list where all consecutive duplicated elements are collapsed to a single element.

A

dedup(enumerable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Enumerates the enumerable, returning a list where all elements that return the same value from a function are collapsed to a single element.

A

dedup_by(enumerable, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Deletes the elements from the start or end of enumerable

A

drop(enumerable, amount)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Returns a list with every nth element in the enumerable dropped, starting with the first element.

A

drop_every(enumerable, nth)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Drops elements at the beginning of the enumerable while fun returns a truthy value.

A

drop_while(enumerable, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Invokes the given fun for each element in the enumerable.

A

each(enumerable, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Returns true if no elements in enumerable

A

empty?(enumerable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Finds the element at the given index (zero-based). and returns {:ok, element} or :error

A

fetch(enumerable, index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Finds the element at the given index (zero-based). Raises if index is out of bounds.

A

fetch!(enumerable, index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Returns the elements for which a function returns a truthy value

A

filter(enumerable, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Returns the first element for which fun returns a truthy value. If no such element is found, returns default.

A

find(enumerable, default \ nil, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Similar to find/3, but returns the index (zero-based) of the element instead of the element itself.

A

find_index(enumerable, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Similar to find/3, but returns the value of the function invocation instead of the element itself.
find_value(enumerable, default \\ nil, fun)
26
Maps the given fun over enumerable and flattens the result.
flat_map(enumerable, fun)
27
Maps and reduces an enumerable, flattening the given results (only one level deep).
flat_map_reduce(enumerable, acc, fun)
28
Returns a map with keys as unique elements of enumerable and values as the count of every element.
frequencies(enumerable)
29
Returns a map with keys as unique elements given by key_fun and values as the count of every element.
frequencies_by(enumerable, key_fun)
30
Splits the enumerable into groups based on key_fun.
group_by(enumerable, key_fun, value_fun \\ fn x -> x end)
31
Intersperses element between each element of the enumeration.
intersperse(enumerable, element)
32
Inserts the given enumerable into a collectable.
into(enumerable, collectable)
33
Inserts the given enumerable into a collectable according to the transformation function.
into(enumerable, collectable, transform)
34
Turn an enumerable into a binary with a joiner
join(enumerable, joiner \\ "")
35
Returns a list where each element is the result of invoking fun on each corresponding element of enumerable.
map(enumerable, fun)
36
Returns a list of results of invoking fun on every nth element of enumerable, starting with the first element.
map_every(enumerable, nth, fun)
37
Maps and intersperses the given enumerable in one pass.
map_intersperse(enumerable, separator, mapper)
38
Maps and joins the given enumerable in one pass.
map_join(enumerable, joiner \\ "", mapper)
39
Invokes the given function to each element in the enumerable to reduce it to a single element, while keeping an accumulator.
map_reduce(enumerable, acc, fun)
40
Returns the maximal element in the enumerable according to Erlang's term ordering.
max(enumerable, sorter \\ &>=/2, empty_fallback \\ fn -> raise(Enum.EmptyError) end)
41
Returns the maximal element in the enumerable as calculated by the given fun.
max_by(enumerable, fun, sorter \\ &>=/2, empty_fallback \\ fn -> raise(Enum.EmptyError) end)
42
Checks if element exists within the enumerable.
member?(enumerable, element)
43
Returns the minimal element in the enumerable according to Erlang's term ordering.
min(enumerable, sorter \\ &<=/2, empty_fallback \\ fn -> raise(Enum.EmptyError) end)
44
Returns the minimal element in the enumerable as calculated by the given fun.
min_by(enumerable, fun, sorter \\ &<=/2, empty_fallback \\ fn -> raise(Enum.EmptyError) end)
45
Returns a tuple with the minimal and the maximal elements in the enumerable according to Erlang's term ordering.
min_max(enumerable, empty_fallback \\ fn -> raise(Enum.EmptyError) end)
46
Returns a tuple with the minimal and the maximal elements in the enumerable as calculated by the given function.
min_max_by(enumerable, fun, empty_fallback \\ fn -> raise(Enum.EmptyError) end)
47
Returns a random element of an enumerable.
random(enumerable)
48
Invokes fun for each element in the enumerable with the accumulator.
reduce(enumerable, fun)
49
Invokes fun for each element in the enumerable with the accumulator.
reduce(enumerable, acc, fun)
50
Reduces enumerable until fun returns {:halt, term}.
reduce_while(enumerable, acc, fun)
51
Returns a list of elements in enumerable excluding those for which the function fun returns a truthy value.
reject(enumerable, fun)
52
Returns a list of elements in enumerable in reverse order.
reverse(enumerable)
53
Reverses the elements in enumerable, appends the tail, and returns it as a list.
reverse(enumerable, tail)
54
Reverses the enumerable in the range from initial start_index through count elements.
reverse_slice(enumerable, start_index, count)
55
Applies the given function to each element in the enumerable, storing the result in a list and passing it as the accumulator for the next computation. Uses the first element in the enumerable as the starting value.
scan(enumerable, fun)
56
Applies the given function to each element in the enumerable, storing the result in a list and passing it as the accumulator for the next computation. Uses the given acc as the starting value.
scan(enumerable, acc, fun)
57
Returns a list with elements in random order
shuffle(enumerable)
58
Returns a subset list of the given enumerable by index_range.
slice(enumerable, index_range)
59
Returns a subset list of the given enumerable, from start_index (zero-based) with amount number of elements if available.
slice(enumerable, start_index, amount)
60
Sorts the enumerable according to Erlang's term ordering.
sort(enumerable)
61
Sorts the enumerable by the given function.
sort(enumerable, fun)
62
Sorts the mapped results of the enumerable according to the provided sorter function.
sort_by(enumerable, mapper, sorter \\ &<=/2)
63
Splits the enumerable into two enumerables, leaving count elements in the first one.
split(enumerable, count)
64
Splits enumerable in two at the position of the element for which fun returns a falsy value (false or nil) for the first time.
split_while(enumerable, fun)
65
Splits the enumerable in two lists according to the given function fun.
split_with(enumerable, fun)
66
Returns the sum of all elements.
sum(enumerable)
67
Takes an amount of elements from the beginning or the end of the enumerable.
take(enumerable, amount)
68
Returns a list of every nth element in the enumerable, starting with the first element.
take_every(enumerable, nth)
69
Takes count random elements from enumerable.
take_random(enumerable, count)
70
Takes the elements from the beginning of the enumerable while fun returns a truthy value.
take_while(enumerable, fun)
71
Converts enumerable to a list.
to_list(enumerable)
72
Enumerates the enumerable, removing all duplicated elements.
uniq(enumerable)
73
Enumerates the enumerable, by removing the elements for which function fun returned duplicate elements.
uniq_by(enumerable, fun)
74
Opposite of zip/2. Extracts two-element tuples from the given enumerable and groups them together.
unzip(enumerable)
75
Returns the enumerable with each element wrapped in a tuple alongside its index.
with_index(enumerable, offset \\ 0)
76
Zips corresponding elements from a finite collection of enumerables into one list of tuples.
zip(enumerables)
77
Zips corresponding elements from two enumerables into one list of tuples.
zip(enumerable1, enumerable2)