Loading...
Preparing your coding drills
Comprehensive reference for 35 Clojure methods across 7 categories.
map
Returns a lazy sequence consisting of the result of applying f to each item in coll. When multiple collections are provided, f is applied to corresponding items from each collection.
filter
Returns a lazy sequence of the items in coll for which (pred item) returns a logically true value.
reduce
Reduces a collection to a single value by applying f, a function of two arguments, to an accumulator and each element. If init is not supplied, the first item of coll is used.
first
Returns the first item in the collection. If coll is nil or empty, returns nil.
rest
Returns a possibly empty sequence of the items after the first. Returns an empty sequence (not nil) when there are no more items.
cons
Returns a new seq where x is the first element and seq is the rest.
into
Returns a new collection consisting of to with all items from from conj-ed onto it. Supports an optional transducer.
take
Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n.
sort
Returns a sorted sequence of the items in coll. Uses natural ordering by default, or a custom comparator if provided.
clojure.string/split
Splits string s on a regular expression re. Returns a vector of strings.
clojure.string/join
Returns a string of all elements in coll, separated by an optional separator.
clojure.string/trim
Removes leading and trailing whitespace from string s.
clojure.string/replace
Replaces all instances of match with replacement in string s. Match can be a string or regex.
assoc
Returns a new map with the given key-value pair(s) added or updated. When used with vectors, sets the value at the given index.
dissoc
Returns a new map without the entry for the given key(s). If the key is not present, returns the map unchanged.
get
Returns the value mapped to key in the associative collection. Returns not-found or nil if the key is not present.
merge
Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping from the latter map is used.
update
Returns a new map with the value at key updated by applying function f to the old value and any additional args. If the key does not exist, f is applied to nil.
conj
Returns a new set with the element(s) added. conj is the primary way to add elements to any Clojure collection; for sets, duplicates are ignored.
disj
Returns a new set without the specified element(s). If the element is not present, returns the set unchanged.
clojure.set/union
Returns a set that is the union of the input sets: all elements from all sets combined.
comp
Takes a set of functions and returns a function that is the composition of those functions. The returned function takes a variable number of args, applies the rightmost function, then applies each remaining function to the result, right-to-left.
partial
Takes a function f and fewer than the normal arguments to f, and returns a function that takes the remaining arguments. When called, the returned function applies f to the original arguments followed by the new ones.
juxt
Takes a set of functions and returns a function that is the juxtaposition of those functions. The returned function takes any number of args and returns a vector containing the result of applying each function to the args.
apply
Applies function f to the argument list formed by prepending any intervening arguments to args. The last argument must be a sequence.
complement
Takes a function f and returns a function that takes the same arguments as f, has the same effects if any, and returns the opposite truth value.
nil?
Returns true if x is nil, false otherwise.
empty?
Returns true if coll has no items (its seq is nil). Works on collections, strings, and nil.
every?
Returns true if (pred x) is logical true for every x in coll, else false.
some
Returns the first logical true value of (pred x) for any x in coll, else nil. Note: returns the value of (pred x), not x itself.
range
Returns a lazy sequence of numbers from start (inclusive) to end (exclusive), by step. With no arguments, returns an infinite sequence of natural numbers starting at 0.
atom
Creates and returns an Atom with an initial value of x. Atoms provide a way to manage shared, synchronous, independent state with atomic compare-and-set semantics.
swap!
Atomically swaps the value of atom to be (apply f current-value-of-atom args). Returns the new value. The function f should be free of side effects, as it may be called multiple times due to retries.
let
Evaluates the expressions in body with the local bindings established. Bindings are a vector of name-value pairs evaluated sequentially.
loop/recur
Establishes local bindings and a recursion point. recur rebinds the loop variables and jumps back to the loop head, enabling efficient iteration without consuming stack.