Loading...
Preparing your coding drills
Comprehensive reference for 37 Haskell methods across 7 categories.
map
Applies a function to every element of a list, returning a new list of the results.
filter
Returns a list of elements that satisfy the given predicate.
foldl
Left-associative fold of a list. Reduces a list to a single value by applying a binary function from the left with an initial accumulator.
foldr
Right-associative fold of a list. Reduces a list by applying a binary function from the right with an initial accumulator.
head
Returns the first element of a non-empty list. Throws an error on an empty list.
tail
Returns all elements of a non-empty list except the first. Throws an error on an empty list.
zip
Takes two lists and returns a list of pairs, pairing elements at the same position. Stops at the shorter list.
take
Returns the first n elements of a list. If the list has fewer than n elements, returns the entire list.
drop
Drops the first n elements of a list and returns the rest. If the list has fewer than n elements, returns an empty list.
concat
Concatenates a list of lists into a single list.
reverse
Returns the elements of a list in reverse order.
length
Returns the number of elements in a foldable structure (commonly a list).
elem
Tests whether an element is in a foldable structure (commonly a list).
concatMap
Maps a function over a list and concatenates the results. Equivalent to concat . map f.
words
Splits a string into a list of words, delimited by whitespace. Consecutive whitespace is treated as a single delimiter.
unwords
Joins a list of words into a single string with spaces between them.
lines
Splits a string on newline characters, returning a list of lines.
show
Converts a value to its String representation. The type must be an instance of the Show type class.
fromMaybe
Extracts the value from a Maybe, returning a default value if it is Nothing.
isJust
Returns True if the Maybe value is Just, False if it is Nothing.
isNothing
Returns True if the Maybe value is Nothing, False if it is Just.
either
Case analysis on Either. Applies the first function to Left values and the second function to Right values.
(.)
Function composition operator. Composes two functions so that (f . g) x equals f (g x).
($)
Application operator. Applies a function to an argument. Has the lowest precedence and is right-associative, so it is commonly used to avoid parentheses.
flip
Takes a binary function and returns a version with the argument order reversed.
const
Returns a function that always returns its first argument, ignoring the second.
id
The identity function. Returns its argument unchanged.
fst
Extracts the first component of a pair (2-tuple).
snd
Extracts the second component of a pair (2-tuple).
swap
Swaps the components of a pair.
compare
Compares two values and returns an Ordering (LT, EQ, or GT). Part of the Ord type class.
min
Returns the smaller of two values. Part of the Ord type class.
max
Returns the larger of two values. Part of the Ord type class.
succ
Returns the successor of a value. Part of the Enum type class. Throws an error if there is no successor.
putStrLn
Writes a string to standard output, followed by a newline character.
getLine
Reads a line of input from standard input, stripping the trailing newline.
print
Outputs a value to standard output using its Show instance, followed by a newline. Equivalent to putStrLn . show.