Core functions
The 329 names that (doc ...) knows about, grouped as in docs.clj. The REPL prints the same text: (doc map). Names that clove shares with Clojure behave as in Clojure; the Clojure cheatsheet covers them in more depth.
Sequences
map
(map f) (map f coll) (map f c1 c2) (map f c1 c2 & colls)
Returns a lazy sequence of applying f to each item of coll (or to the items of multiple colls in parallel, stopping at the shortest). (map f) returns a transducer.
filter
(filter pred) (filter pred coll)
Returns a lazy sequence of the items in coll for which (pred item) is logical true. (filter pred) returns a transducer.
remove
(remove pred) (remove pred coll)
Returns a lazy sequence of the items for which (pred item) is logical false.
reduce
(reduce f coll) (reduce f init coll)
(reduce f coll) or (reduce f init coll): applies f to an accumulator and each item, left to right. With no init, first two items seed the call; empty coll => (f).
reductions
(reductions f coll) (reductions f init coll)
Returns a lazy seq of the intermediate values of a reduction, starting with init (or the first item).
reduce-kv
(reduce-kv f init coll)
Reduces an associative collection: (f acc key val) for every entry. Vectors use their indices as keys.
mapcat
(mapcat f) (mapcat f & colls)
Applies f to every item and concatenates the (collection) results, lazily.
keep-indexed
(keep-indexed f) (keep-indexed f coll)
Lazy sequence of the non-nil results of (f index item).
take-while
(take-while pred) (take-while pred coll)
Lazy items from the front while (pred item) is true.
drop-while
(drop-while pred) (drop-while pred coll)
Lazy items after the leading run where (pred item) is true.
nth
(nth coll index) (nth coll index not-found)
The item at index n. Throws when out of bounds unless a not-found is given.
conj
(conj coll) (conj coll x) (conj coll x & xs)
Adds item(s) to a collection at its natural insertion point: vectors append, lists prepend, sets/maps add.
concat
(concat) (concat x) (concat x y) (concat x y & zs)
Lazy concatenation of any number of collections.
into
(into to from) (into to xform from)
Adds every item of `from` onto `to` (conj semantics); (into to xform from) applies a transducer.
range
(range) (range end) (range start end) (range start end step)
(range), (range end), (range start end step): lazy seq of numbers. No args = infinite.
interleave
(interleave) (interleave c1) (interleave c1 c2) (interleave c1 c2 & colls)
First items of each coll, then second items, etc., stopping at the shortest.
partition
(partition n coll) (partition n step coll) (partition n step pad coll)
Lazy blocks of n items (optionally stepped/padded); incomplete tail block is dropped unless padded.
partition-all
(partition-all n) (partition-all n coll) (partition-all n step coll)
Like partition but keeps the incomplete final block.
partition-by
(partition-by f) (partition-by f coll)
Splits coll each time (f item) changes value, lazily.
sort-by
(sort-by keyfn coll) (sort-by keyfn comp coll)
Sorts by (keyfn item), optionally with a comparator.
doall
(doall coll) (doall n coll)
Forces a lazy sequence completely; returns it. Use for side effects held in a lazy seq.
realized?
Whether a delay/lazy value has been forced (clove: coarse).
line-seq
Lazy seq of lines from a reader.
tree-seq
(tree-seq branch? children root)
Lazy depth-first walk: branch? decides descent, children expands.
Collections
get
(get map key) (get map key not-found)
The value at key (or index), or not-found/nil. Works on maps, vectors, sets, strings.
assoc
(assoc map key val) (assoc map key val & kvs)
Map with key(s) mapped to val(s); on vectors, sets the index (append at count).
update
(update m k f) (update m k f x) (update m k f x y) (update m k f x y & more)
Map with the value at k replaced by (f old & args).
contains?
(contains? coll key)
Whether the key (or index) is present — NOT a value search; use `some` for that.
subseq
Entries of a sorted collection in a key range, e.g. (subseq sm >= 5).
rsubseq
Like subseq, descending.
transient
(transient coll)
A mutable-in-place edition of a vector/map/set for batch building; finish with persistent!.
int-array
(int-array size) (int-array size init-or-seq)
(int-array n), (int-array n init), (int-array coll): a flat mutable int64 array (clove native). Use aget/aset/alength.
Functions & control
apply
(apply f args) (apply f x args) (apply f x y args) (apply f x y z & args)
Calls f with the items of the final argument spliced in as arguments.
partial
(partial f) (partial f arg1) (partial f arg1 arg2) (partial f arg1 arg2 arg3 & more)
A fn with some leading arguments preapplied.
comp
(comp) (comp f) (comp f g) (comp f g & fs)
Right-to-left function composition: ((comp f g) x) is (f (g x)).
fnil
(fnil f x) (fnil f x y) (fnil f x y z)
A fn that substitutes defaults for leading nil arguments before calling f.
every-pred
A pred that is true when ALL given preds are true.
some-fn
A fn returning the first logical-true result among the given fns.
memoize
Caches f's results by argument list.
trampoline
Calls f; while the result is a fn, calls it — flat mutual recursion.
if-let
Binds then branches: (if-let [x expr] then else) — then runs with x bound when expr is truthy.
when-let
(when-let [x expr] body...) — body runs with x bound when expr is truthy.
if-some
Like if-let but tests (some? expr), so false is a hit.
when-some
Like when-let but tests (some? expr).
cond
Pairs of test/expr: value of the expr after the first truthy test.
condp
(condp pred expr & clauses): matches expr against clause keys with pred.
case
Constant-time dispatch on identical(ish) constants; throws without a default.
cond->
Threads x through the exprs whose paired tests are truthy.
cond->>
Like cond-> threading last.
as->
Threads through forms binding each result to the given name.
some->
Threads while values are non-nil; stops at the first nil.
some->>
Like some-> threading last.
doto
Evaluates x, threads it as first arg through the forms (for side effects), returns x.
dotimes
(dotimes [i n] body): runs body n times with i bound 0..n-1.
doseq
Iterates for side effects with for-style bindings (:let/:when/:while); returns nil.
for
Lazy list comprehension with :let/:when/:while modifiers.
loop
Establishes bindings that recur re-enters with new values.
recur
Rebinds the enclosing loop/fn bindings and jumps back — constant-stack iteration.
while
Runs body repeatedly while test is truthy.
run!
(reduce (fn [_ x] (f x)) nil coll) — eager side effects, returns nil.
Numbers
gcd
Greatest common divisor (clove extension).
parse-long
The string as a long, or nil if it isn't one.
parse-double
The string as a double, or nil.
compare
(compare x y)
-1/0/1 comparator over comparable values (numbers, strings, keywords, vectors...).
Strings
str/join
(str/join coll) (str/join separator coll)
Concatenates the collection's items, optionally separated: (str/join ", " xs).
str/replace
(str/replace s match replacement)
Replaces all matches of a string or #"regex" (with $1.. group refs or a fn).
str/index-of
(str/index-of s value) (str/index-of s value from-index)
First index of a substring/char, or nil.
str/last-index-of
(str/last-index-of s value) (str/last-index-of s value from-index)
Last index of a substring/char, or nil.
Regex
re-find
(re-find re s)
First match of the pattern in s: the string, or [match groups...] when the pattern has groups.
re-replace
clove: replace all matches, with $1..$9 group refs in the replacement.
State
swap!
(swap! atom f) (swap! atom f x) (swap! atom f x y) (swap! atom f x y & args)
Sets an atom to (f current args...); returns the new value.
swap-vals!
Like swap! but returns [old new].
reset-vals!
Like reset! but returns [old new].
compare-and-set!
Sets the atom to new only if it currently holds old; returns success.
delay
Defers body until the first deref, then caches.
force
Derefs a delay, passes other values through.
Predicates & misc
integer?
Whether x is any integer.
double?
Whether x is a double.
sorted?
Whether x is a sorted collection.
keyword
(keyword name) (keyword ns name)
Makes a keyword from a name (and optional namespace): (keyword "a" "b") => :a/b.
identical?
Pointer equality — same object.
hash
The value's hash code (consistent with =).
macroexpand-1
One step of macro expansion for the form.
macroexpand
Repeated macroexpand-1 until the head is no longer a macro.
time
Evaluates body, prints elapsed time, returns the value.
assert
Throws when x is falsy (with optional message).
ex-info
An exception carrying a message and a data map (and optional cause).
ex-message
The message of an exception.
ex-data
The data map of an ex-info exception, else nil.
ex-cause
The cause of an exception, or nil.
with-out-str
Evaluates body capturing everything printed, returning it as a string.
doc
Prints documentation for the named binding: (doc map).
source
Prints the (re-read) source of a fn defined from Clojure code: (source my-fn).
apropos
All defined names containing the string: (apropos "index").
find-doc
Prints docs for every binding whose name or docstring matches.
Multimethods & protocols
defmulti
Defines a multimethod dispatching on (dispatch-fn args...).
defmethod
Adds a method implementation for a dispatch value.
defprotocol
Declares a named set of methods dispatched on the first argument's type.
defrecord
Defines a named map-like type with fixed fields and protocol support.
deftype
Defines a named type with fields (clove: represented as a tagged map).
derive
Adds a parent relationship in the (global) hierarchy.
isa?
Hierarchy-aware type/tag relation (vectors compare element-wise).
Batteries
fs/exists?
Whether the path exists.
fs/directory?
Whether the path is a directory.
fs/regular-file?
Whether the path is a regular file.
fs/list-dir
Sequence of entries in a directory.
fs/create-dir
Creates the directory (and parents); true on success.
fs/delete
Deletes a file or (empty) directory; true on success.
fs/move
Renames/moves src to dst; true on success.
fs/copy
Copies src to dst.
fs/file-name
The final path segment.
fs/parent
The parent directory of the path, or nil.
fs/extension
The file extension without the dot, or nil.
fs/temp-dir
The system temp directory.
fs/cwd
The current working directory.
http/serve
Starts the HTTP server on the csp event loop; returns the listening socket (drive with (csp/run!)). Handler gets a request map, returns a string or {:status :headers :body}.
http/run-server
Starts the HTTP server and blocks, driving the csp event loop.
http/router
Builds a handler from route entries [[method path-pattern handler] ...].
http/request
Performs an HTTP request from {:method :url :headers :body}; returns a channel of the response map.
http/get
HTTP GET of a url; returns a channel of the response map.
http/post
HTTP POST of a body to a url; returns a channel of the response map.
json/parse
Parses a JSON string to Clojure data ((json/parse s) or (json/parse s {:keywords? true})).
json/write
Renders Clojure data as a JSON string.
peg/match
Matches a Janet-style PEG (pattern data, grammar map with :main, or compiled) at start of text; returns the capture vector or nil. (peg/match peg text ?start & args).
peg/compile
Compiles a PEG pattern once; the result is a fn (m text ?start & args) => captures, accepted anywhere a pattern is.
peg/find
Index of the first position at/after start where the PEG matches, or nil.
peg/find-all
Vector of every position in text where the PEG matches.
peg/replace
Replaces the first PEG match in text with subst: a string, or a fn of (matched-text & captures).
peg/replace-all
Replaces every PEG match in text with subst (string or fn of (matched-text & captures)).
process/sh
Runs a shell command, returns {:exit :out} (stderr folded into :out).
process/shell
Like process/sh but throws ex-info on nonzero exit.
process/out
The trimmed stdout of running the command.
process/escape
Shell-escapes a string for safe interpolation.
Special forms & core macros
if
(if test then else?)
Special form. Evaluates test; if truthy (anything but nil/false), evaluates and returns then, otherwise else (or nil).
let
(let [bindings*] exprs*)
Special form. Binds names to values in order (later bindings see earlier ones); evaluates body with them in scope. Destructuring supported.
fn
(fn name? [params*] exprs*) (fn name? ([params*] exprs*) +)
Special form. An anonymous function; multiple arity clauses allowed, & gathers rest args. #(...) is shorthand with % %1 %2.
def
(def symbol doc-string? init?)
Special form. Interns a root binding for the symbol, optionally with a docstring and init value.
loop
(loop [bindings*] exprs*)
Special form. Like let, but marks a recur target: (recur ...) rebinds the loop bindings and jumps back without consuming stack.
recur
(recur exprs*)
Special form. Rebinds the enclosing loop/fn bindings to the given values and jumps back — clove's tail call. Must be in tail position.
var
(var symbol)
Special form. Returns the Var named by the symbol (also #'sym). Its meta carries :name/:doc/:arglists.
throw
(throw expr)
Special form. Throws a value; catch it with try/catch. Use ex-info to build data-carrying exceptions.
try
(try exprs* (catch Exception e exprs*) ? (finally exprs*) ?)
Special form. Evaluates body; on a throw, the first matching catch clause runs with the exception bound; finally always runs.
when
(when test exprs*)
Macro. Evaluates body when test is truthy, else nil. No else branch — use if for that.
when-let
(when-let [sym test] exprs*)
Macro. Binds the value of test; evaluates body when it is truthy.
when-some
(when-some [sym test] exprs*)
Macro. Like when-let but tests for non-nil rather than truthy.
if-let
(if-let [sym test] then else?)
Macro. Binds the value of test; if truthy evaluates then with it bound, else else.
if-some
(if-some [sym test] then else?)
Macro. Like if-let but tests for non-nil (false counts as some).
and
(and) (and x) (and x & next)
Macro. Evaluates left to right, returns the first falsey value or the last value. () => true.
or
(or) (or x) (or x & next)
Macro. Evaluates left to right, returns the first truthy value or the last value. () => nil.
->
(-> x & forms)
Macro. Thread-first: inserts each result as the SECOND item of the next form. (-> x (f a) g) => (g (f x a)).
->>
(->> x & forms)
Macro. Thread-last: inserts each result as the LAST item of the next form. (->> x (f a) g) => (g (f a x)).
as->
(as-> expr name & forms)
Macro. Threads x through forms with an explicit name for the previous result.
cond->
(cond-> expr & test-form-pairs)
Macro. Threads expr through the forms whose paired test is truthy (tests are NOT threaded).
doto
(doto x & forms)
Macro. Evaluates x, calls each form with x inserted second (for side effects), returns x.
dotimes
(dotimes [name n] exprs*)
Macro. Runs body n times with the name bound to 0..n-1; returns nil.
doseq
(doseq [seq-exprs*] exprs*)
Macro. Iterates the seq(s) for side effects; supports :let :when :while like for. Returns nil.
for
(for [seq-exprs*] body-expr)
Macro. List comprehension: lazy seq of body evaluated across the bindings; modifiers :let :when :while.
defn
(defn name doc-string? [params*] exprs*) (defn name doc-string? ([params*] exprs*) +)
Macro. (def name (fn ...)) with docstring and multi-arity support; registers the docstring for (doc name).
defn-
(defn- name doc-string? [params*] exprs*)
Macro. Like defn but marks the var private to its namespace.
defmacro
(defmacro name doc-string? [params*] exprs*)
Macro. Defines a macro: the fn receives unevaluated forms and returns a replacement form.
declare
(declare & names)
Macro. Forward-declares names so later defs can be referenced before definition.
binding
(binding [var-val-pairs*] exprs*)
Macro. Temporarily rebinds dynamic (root) vars for the extent of the body, restoring on exit.
with-redefs
(with-redefs [var-val-pairs*] exprs*)
Macro. Temporarily rebinds the root values of vars for the extent of the body, restoring them afterwards, even on a throw. Visible to all code, unlike binding.
letfn
(letfn [(name [params*] exprs*) +] exprs*)
Macro. Binds locally-scoped, mutually recursive fns for the body.
case
(case e & test-result-pairs default?)
Macro. Constant-time dispatch on compile-time literal test values; last arg is the default, throws when absent and unmatched.
condp
(condp pred expr & clauses)
Macro. (condp pred expr ...) — first clause where (pred test-val expr) is truthy.
require
(require & specs)
Loads namespaces from *load-path* (name → path: . becomes /, - becomes _). Supports [ns :as alias] and [ns :refer [syms]].
with-out-str
(with-out-str & body)
Macro. Evaluates body capturing *out*; returns what it printed as a string.
lazy-seq
(lazy-seq & body)
Macro. Wraps body in an unrealized lazy sequence; realized once on first seq access.