Loading...
Preparing your coding drills
Comprehensive reference for 31 Scala methods across 7 categories.
map
Builds a new collection by applying a function to all elements of this list.
filter
Selects all elements of this list which satisfy a predicate.
flatMap
Builds a new collection by applying a function to all elements and flattening the results.
foldLeft
Applies a binary operator to a start value and all elements of this list, going left to right.
reduce
Reduces the elements of this collection using the specified associative binary operator.
zip
Returns a list of pairs formed from this list and another iterable by combining corresponding elements.
split
Splits this string around matches of the given regular expression.
mkString
Displays all elements of this collection in a string using a separator, with optional start and end strings.
trim
Returns a copy of the string with leading and trailing whitespace removed.
contains
Tests whether this string contains the specified sequence of characters.
getOrElse
Returns the value associated with a key, or a default value if the key is not contained in the map.
updated
Creates a new map with an additional or updated key/value mapping. The original map is not modified.
keys
Returns an iterable containing all keys of this map.
filterKeys
Filters this map by retaining only keys satisfying a predicate. Returns a lazy view in Scala 2.13+.
Tests whether this set contains a given value as an element.
union
Computes the union of this set and another set, returning all elements from both.
intersect
Computes the intersection of this set and another set, returning elements present in both.
Returns the option value if it is nonempty, otherwise returns the result of evaluating default.
Returns a Some containing the result of applying f to this Option value if it is nonempty, otherwise returns None.
Returns the result of applying f to this Option value if it is nonempty, otherwise returns None. Avoids nested Options.
fold
Returns the result of applying f to the Option value if nonempty, or the value of ifEmpty otherwise.
swap
Swaps the elements of a Tuple2, returning a new tuple with the elements in reverse order.
copy
Creates a shallow copy of a case class instance, optionally replacing specified fields with new values.
productIterator
Returns an iterator over all the elements of this product (tuple or case class).
groupBy
Partitions this collection into a map of collections according to a discriminator function.
partition
Splits this collection into a pair of collections: one with elements satisfying the predicate, and one with elements that do not.
takeWhile
Takes the longest prefix of elements that satisfy the predicate.
sortBy
Sorts this collection according to a transformation function that maps each element to an Ordered value.
distinct
Selects all the elements of this collection ignoring duplicates. Preserves the order of first occurrence.
collect
Builds a new collection by applying a partial function to all elements on which the function is defined. Combines filter and map in a single step.
sliding
Groups elements into fixed-size blocks by passing a sliding window over them.