Elixir Enum Functions Flashcards

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
Q

Similar to find/3, but returns the value of the function invocation instead of the element itself.

A

find_value(enumerable, default \ nil, fun)

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

Maps the given fun over enumerable and flattens the result.

A

flat_map(enumerable, fun)

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

Maps and reduces an enumerable, flattening the given results (only one level deep).

A

flat_map_reduce(enumerable, acc, fun)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
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
29
Q

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

A

frequencies_by(enumerable, key_fun)

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

Splits the enumerable into groups based on key_fun.

A

group_by(enumerable, key_fun, value_fun \ fn x -> x end)

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

Intersperses element between each element of the enumeration.

A

intersperse(enumerable, element)

32
Q

Inserts the given enumerable into a collectable.

A

into(enumerable, collectable)

33
Q

Inserts the given enumerable into a collectable according to the transformation function.

A

into(enumerable, collectable, transform)

34
Q

Turn an enumerable into a binary with a joiner

A

join(enumerable, joiner \ “”)

35
Q

Returns a list where each element is the result of invoking fun on each corresponding element of enumerable.

A

map(enumerable, fun)

36
Q

Returns a list of results of invoking fun on every nth element of enumerable, starting with the first element.

A

map_every(enumerable, nth, fun)

37
Q

Maps and intersperses the given enumerable in one pass.

A

map_intersperse(enumerable, separator, mapper)

38
Q

Maps and joins the given enumerable in one pass.

A

map_join(enumerable, joiner \ “”, mapper)

39
Q

Invokes the given function to each element in the enumerable to reduce it to a single element, while keeping an accumulator.

A

map_reduce(enumerable, acc, fun)

40
Q

Returns the maximal element in the enumerable according to Erlang’s term ordering.

A

max(enumerable, sorter \ &>=/2, empty_fallback \ fn -> raise(Enum.EmptyError) end)

41
Q

Returns the maximal element in the enumerable as calculated by the given fun.

A

max_by(enumerable, fun, sorter \ &>=/2, empty_fallback \ fn -> raise(Enum.EmptyError) end)

42
Q

Checks if element exists within the enumerable.

A

member?(enumerable, element)

43
Q

Returns the minimal element in the enumerable according to Erlang’s term ordering.

A

min(enumerable, sorter \ &<=/2, empty_fallback \ fn -> raise(Enum.EmptyError) end)

44
Q

Returns the minimal element in the enumerable as calculated by the given fun.

A

min_by(enumerable, fun, sorter \ &<=/2, empty_fallback \ fn -> raise(Enum.EmptyError) end)

45
Q

Returns a tuple with the minimal and the maximal elements in the enumerable according to Erlang’s term ordering.

A

min_max(enumerable, empty_fallback \ fn -> raise(Enum.EmptyError) end)

46
Q

Returns a tuple with the minimal and the maximal elements in the enumerable as calculated by the given function.

A

min_max_by(enumerable, fun, empty_fallback \ fn -> raise(Enum.EmptyError) end)

47
Q

Returns a random element of an enumerable.

A

random(enumerable)

48
Q

Invokes fun for each element in the enumerable with the accumulator.

A

reduce(enumerable, fun)

49
Q

Invokes fun for each element in the enumerable with the accumulator.

A

reduce(enumerable, acc, fun)

50
Q

Reduces enumerable until fun returns {:halt, term}.

A

reduce_while(enumerable, acc, fun)

51
Q

Returns a list of elements in enumerable excluding those for which the function fun returns a truthy value.

A

reject(enumerable, fun)

52
Q

Returns a list of elements in enumerable in reverse order.

A

reverse(enumerable)

53
Q

Reverses the elements in enumerable, appends the tail, and returns it as a list.

A

reverse(enumerable, tail)

54
Q

Reverses the enumerable in the range from initial start_index through count elements.

A

reverse_slice(enumerable, start_index, count)

55
Q

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.

A

scan(enumerable, fun)

56
Q

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.

A

scan(enumerable, acc, fun)

57
Q

Returns a list with elements in random order

A

shuffle(enumerable)

58
Q

Returns a subset list of the given enumerable by index_range.

A

slice(enumerable, index_range)

59
Q

Returns a subset list of the given enumerable, from start_index (zero-based) with amount number of elements if available.

A

slice(enumerable, start_index, amount)

60
Q

Sorts the enumerable according to Erlang’s term ordering.

A

sort(enumerable)

61
Q

Sorts the enumerable by the given function.

A

sort(enumerable, fun)

62
Q

Sorts the mapped results of the enumerable according to the provided sorter function.

A

sort_by(enumerable, mapper, sorter \ &<=/2)

63
Q

Splits the enumerable into two enumerables, leaving count elements in the first one.

A

split(enumerable, count)

64
Q

Splits enumerable in two at the position of the element for which fun returns a falsy value (false or nil) for the first time.

A

split_while(enumerable, fun)

65
Q

Splits the enumerable in two lists according to the given function fun.

A

split_with(enumerable, fun)

66
Q

Returns the sum of all elements.

A

sum(enumerable)

67
Q

Takes an amount of elements from the beginning or the end of the enumerable.

A

take(enumerable, amount)

68
Q

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

A

take_every(enumerable, nth)

69
Q

Takes count random elements from enumerable.

A

take_random(enumerable, count)

70
Q

Takes the elements from the beginning of the enumerable while fun returns a truthy value.

A

take_while(enumerable, fun)

71
Q

Converts enumerable to a list.

A

to_list(enumerable)

72
Q

Enumerates the enumerable, removing all duplicated elements.

A

uniq(enumerable)

73
Q

Enumerates the enumerable, by removing the elements for which function fun returned duplicate elements.

A

uniq_by(enumerable, fun)

74
Q

Opposite of zip/2. Extracts two-element tuples from the given enumerable and groups them together.

A

unzip(enumerable)

75
Q

Returns the enumerable with each element wrapped in a tuple alongside its index.

A

with_index(enumerable, offset \ 0)

76
Q

Zips corresponding elements from a finite collection of enumerables into one list of tuples.

A

zip(enumerables)

77
Q

Zips corresponding elements from two enumerables into one list of tuples.

A

zip(enumerable1, enumerable2)