(<- & body)
Used to provide arbitrary input and output values to forms threading in the
style of ->
.
The threaded form will be evaluated although its value will be
discarded.
Used to provide arbitrary input and output values to forms threading in the style of `->`. The threaded form will be evaluated although its value will be discarded.
(<<- & body)
Like <-
but must be used in the context of a form threading in the
style of ->>
.
Like [[<-]] but must be used in the context of a form threading in the style of `->>`.
(>- first-expr last-expr)
A threading arrow fletching used to change the position at which the threaded form will be injected in the threading slots of the threading form. Transitions from a thread-last to a thread-first threading style.
A threading arrow fletching used to change the position at which the threaded form will be injected in the threading slots of the threading form. Transitions from a thread-last to a thread-first threading style.
(>>- first-expr last-expr)
A threading arrow fletching used to change the position at which the threaded form will be injected in the threading slots of the threading form. Transitions from a thread-first to a thread-last threading style.
A threading arrow fletching used to change the position at which the threaded form will be injected in the threading slots of the threading form. Transitions from a thread-first to a thread-last threading style.
(and-> expr & forms)
Threads expr
through each form halting on a nil
or false
result.
Threads like ->
.
Threads `expr` through each form halting on a `nil` or `false` result. Threads like `->`.
(and->> expr & forms)
Threads expr
through each form halting on a nil
or false
result.
Threads like ->>
.
Threads `expr` through each form halting on a `nil` or `false` result. Threads like `->>`.
(defthreading & args)
Defines a threading arrow with variants.
Each variant is defined by a sequence like (name docstring? opts?)
.
The name of each defined threading arrow will consist in the
variant symbol (usually ->
and ->>
) prefixed by name-prefix
if provided.
Same goes for each arrow docstring: it will be prefixed with
doc-prefix
if provided.
The body
will have access to some local variables defined under
the hood:
&threading-variant
(mapped to the variant's name)&threading-opts
(mapped to the variant's opts map if provided)Keep in mind defthreading
defines macros: the body should
return Clojure code, not runtime values.
Example:
Consider this definition of tap
with a custom ->debug
threading variant:
(defmacro ->debug [& forms]
`(-> ~@forms))
(defthreading tap
"Some documentation."
[-> "Some sufix for the documentation."
->> "Another documentation complement"
->debug {:debug true}] ;; No documentation here
[expr & forms]
`(let [result# ~expr]
(when (:debug ~&threading-opts)
(println "debug->:" result#))
(~&threading-variant result# ~@forms)
result#))
(tap->debug 1 (println ": perform some side-effect"))
;; debug->: 1
;; 1 : perform some side-effect.
;; => 1
Defines a threading arrow with variants. Each variant is defined by a sequence like `(name docstring? opts?)`. The name of each defined threading arrow will consist in the variant symbol (usually `->` and `->>`) prefixed by `name-prefix` if provided. Same goes for each arrow docstring: it will be prefixed with `doc-prefix` if provided. The `body` will have access to some local variables defined under the hood: - `&threading-variant` (mapped to the variant's name) - `&threading-opts` (mapped to the variant's opts map if provided) Keep in mind `defthreading` defines macros: the body should return Clojure code, not runtime values. Example: Consider this definition of [[tap]] with a custom `->debug` threading variant: ```clojure (defmacro ->debug [& forms] `(-> ~@forms)) (defthreading tap "Some documentation." [-> "Some sufix for the documentation." ->> "Another documentation complement" ->debug {:debug true}] ;; No documentation here [expr & forms] `(let [result# ~expr] (when (:debug ~&threading-opts) (println "debug->:" result#)) (~&threading-variant result# ~@forms) result#)) (tap->debug 1 (println ": perform some side-effect")) ;; debug->: 1 ;; 1 : perform some side-effect. ;; => 1 ```
(if-> expr test then)
(if-> expr test then else)
Threads expr
through test
then then
or else
. If else
is
not provided, returns expr
when test
fails.
Threads like ->
.
Threads `expr` through `test` then `then` or `else`. If `else` is not provided, returns `expr` when `test` fails. Threads like `->`.
(if->> expr test then)
(if->> expr test then else)
Threads expr
through test
then then
or else
. If else
is
not provided, returns expr
when test
fails.
Threads like ->>
.
Threads `expr` through `test` then `then` or `else`. If `else` is not provided, returns `expr` when `test` fails. Threads like `->>`.
(if-not-> expr test then)
(if-not-> expr test then else)
Threads expr
through test
then then
or else
. If else
is
not provided, returns expr
when test
fails.
Threads like ->
.
Threads `expr` through `test` then `then` or `else`. If `else` is not provided, returns `expr` when `test` fails. Threads like `->`.
(if-not->> expr test then)
(if-not->> expr test then else)
Threads expr
through test
then then
or else
. If else
is
not provided, returns expr
when test
fails.
Threads like ->>
.
Threads `expr` through `test` then `then` or `else`. If `else` is not provided, returns `expr` when `test` fails. Threads like `->>`.
(map-> expr & forms)
For an expr
that will yield a sequence, threads each of its values
through the forms
.
Threads like ->
.
For an `expr` that will yield a sequence, threads each of its values through the `forms`. Threads like `->`.
(map->> expr & forms)
For an expr
that will yield a sequence, threads each of its values
through the forms
.
Threads like ->>
.
For an `expr` that will yield a sequence, threads each of its values through the `forms`. Threads like `->>`.
(map-keys-> expr & forms)
For an expr
that will yield an associative structure, threads each of its
keys through the forms
.
Threads like ->
.
For an `expr` that will yield an associative structure, threads each of its keys through the `forms`. Threads like `->`.
(map-keys->> expr & forms)
For an expr
that will yield an associative structure, threads each of its
keys through the forms
.
Threads like ->>
.
For an `expr` that will yield an associative structure, threads each of its keys through the `forms`. Threads like `->>`.
(map-vals-> expr & forms)
For an expr
that will yield an associative structure, threads each of its
values through the forms
.
Threads like ->
.
For an `expr` that will yield an associative structure, threads each of its values through the `forms`. Threads like `->`.
(map-vals->> expr & forms)
For an expr
that will yield an associative structure, threads each of its
values through the forms
.
Threads like ->>
.
For an `expr` that will yield an associative structure, threads each of its values through the `forms`. Threads like `->>`.
(not-> expr & forms)
Threads expr
through the forms
then returns the negated result.
Threads like ->
.
Threads `expr` through the `forms` then returns the negated result. Threads like `->`.
(not->> expr & forms)
Threads expr
through the forms
then returns the negated result.
Threads like ->>
.
Threads `expr` through the `forms` then returns the negated result. Threads like `->>`.
(or-> expr & forms)
Threads expr
through each expr halting on a non nil
or false
result.
Threads like ->
.
Threads `expr` through each expr halting on a non `nil` or `false` result. Threads like `->`.
(or->> expr & forms)
Threads expr
through each expr halting on a non nil
or false
result.
Threads like ->>
.
Threads `expr` through each expr halting on a non `nil` or `false` result. Threads like `->>`.
(pp-> f & forms)
Like ->
, but prints a debug statement for f
and each expr in forms
.
Like `->`, but prints a debug statement for `f` and each expr in `forms`.
(pp->> f & forms)
Like ->>
, but prints a debug statement for f
and each expr in forms
.
Like `->>`, but prints a debug statement for `f` and each expr in `forms`.
(tap expr & body)
Evaluates expressions in order returning the value of the first. Will thread the first expr into any subsequent threading expr.
(tap 123 (println "yo") (some-> inc println)) ; yo ; 124 ; => 123
Evaluates expressions in order returning the value of the first. Will thread the first expr into any subsequent threading expr. (tap 123 (println "yo") (some-> inc println)) ; yo ; 124 ; => 123
(tap-> expr & forms)
Threads the expr through the forms then returns the value of
the initial expr.
Threads like ->
.
Threads the expr through the forms then returns the value of the initial expr. Threads like `->`.
(tap->> expr & forms)
Threads the expr through the forms then returns the value of
the initial expr.
Threads like ->>
.
Threads the expr through the forms then returns the value of the initial expr. Threads like `->>`.
(when-> expr test & forms)
Threads expr
through test
then the rest of the forms
if it succeeds.
Returns expr
otherwise.
Threads like ->
.
Threads `expr` through `test` then the rest of the `forms` if it succeeds. Returns `expr` otherwise. Threads like `->`.
(when->> expr test & forms)
Threads expr
through test
then the rest of the forms
if it succeeds.
Returns expr
otherwise.
Threads like ->>
.
Threads `expr` through `test` then the rest of the `forms` if it succeeds. Returns `expr` otherwise. Threads like `->>`.
(when-not-> expr test & forms)
Threads expr
through test
then the rest of the forms
if it fails.
Returns expr
otherwise.
Threads like ->
.
Threads `expr` through `test` then the rest of the `forms` if it fails. Returns `expr` otherwise. Threads like `->`.
(when-not->> expr test & forms)
Threads expr
through test
then the rest of the forms
if it fails.
Returns expr
otherwise.
Threads like ->>
.
Threads `expr` through `test` then the rest of the `forms` if it fails. Returns `expr` otherwise. Threads like `->>`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close