Loading...
Preparing your coding drills
Comprehensive reference for 34 Elixir methods across 7 categories.
Enum.map
Returns a list where each element is the result of invoking fun on each corresponding element of the enumerable.
Enum.filter
Filters the enumerable, returning only those elements for which fun returns a truthy value.
Enum.reduce
Invokes fun for each element in the enumerable with the accumulator. The initial value of the accumulator is acc. The function must return the updated accumulator.
Enum.sort
Sorts the enumerable according to Erlang term ordering or a given sorter function.
Enum.find
Returns the first element for which fun returns a truthy value. If no such element is found, returns default.
Enum.any?
Returns true if fun returns a truthy value for at least one element in the enumerable.
Enum.chunk_every
Splits the enumerable into chunks of the given count. An optional step and leftover can control overlap and padding.
Enum.group_by
Splits the enumerable into groups based on key_fun. Returns a map where each key is the grouping value and each value is a list of elements in that group.
Enum.flat_map
Maps the given fun over the enumerable and flattens the result by one level.
String.split
Divides a string into parts based on a pattern. The pattern can be a string, a list of strings, a regular expression, or a compiled pattern.
String.trim
Returns a string where all leading and trailing Unicode whitespace has been removed.
String.replace
Returns a new string where all matches of pattern in subject are replaced with replacement.
String.upcase
Converts all characters in the given string to uppercase according to Unicode rules.
String.contains?
Checks if string contains any of the given contents.
List.first
Returns the first element in the list, or default if the list is empty.
List.last
Returns the last element in the list, or default if the list is empty.
List.flatten
Flattens the given list of nested lists.
++ (list concatenation)
Concatenates two lists. This is a Kernel operator that creates a new list by appending list2 to list1.
Map.get
Gets the value for a specific key in the map. Returns default if key is not present.
Map.put
Puts the given value under key in the map. If the key already exists, it is overwritten.
Map.delete
Deletes the entry for a specific key from the map. If the key does not exist, returns the map unchanged.
Map.merge
Merges two maps into one. If keys exist in both maps, the values from map2 take precedence.
Map.keys
Returns all keys from the map.
IO.puts
Writes the given item to the device, followed by a newline. Returns :ok.
IO.inspect
Inspects and writes the given item to the device, then returns the item itself. Extremely useful for debugging because it can be inserted into pipelines without breaking them.
elem
Accesses the element at the zero-based index in the given tuple.
is_nil
Returns true if term is nil, false otherwise. This is a guard-safe function.
Stream.map
Creates a stream that will apply the given function on each element when enumerated. Unlike Enum.map, this is lazy and does not evaluate until consumed.
Stream.filter
Creates a stream that filters elements according to the given function on enumeration. Lazy counterpart of Enum.filter.
Stream.cycle
Creates a stream that cycles the given enumerable infinitely.
Stream.take
Lazily takes the first count elements from the enumerable and stops enumeration.
case
Matches the given expression against multiple patterns and executes the corresponding block for the first match. Supports guard clauses with when.
cond
Evaluates a series of conditions and executes the block for the first condition that evaluates to a truthy value. Similar to else-if chains in other languages.
with
Chains pattern matches together. If all patterns match, the do block is executed. If any pattern fails to match, the chain stops and the non-matching value is returned (or handled by the else block).