Liking cljdoc? Tell your friends :D

threading.core


*pp-lazy-max*clj

source

<-cljmacro

(<- & 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.
sourceraw docstring

<<-cljmacro

(<<- & 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 `->>`.
sourceraw docstring

>-cljmacro

(>- 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.
sourceraw docstring

>->cljmacro

(>-> expr threaded-expr)
source

>->>cljmacro

(>->> expr threaded-expr)
source

>>-cljmacro

(>>- 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.
sourceraw docstring

>>->cljmacro

(>>-> threaded-expr expr)
source

>>->>cljmacro

(>>->> threaded-expr expr)
source

and->cljmacro

(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 `->`.
sourceraw docstring

and->>cljmacro

(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 `->>`.
sourceraw docstring

defthreadingcljmacro

(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
```
sourceraw docstring

if->cljmacro

(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 `->`.
sourceraw docstring

if->>cljmacro

(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 `->>`.
sourceraw docstring

if-not->cljmacro

(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 `->`.
sourceraw docstring

if-not->>cljmacro

(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 `->>`.
sourceraw docstring

map->cljmacro

(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 `->`.
sourceraw docstring

map->>cljmacro

(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 `->>`.
sourceraw docstring

map-keys->cljmacro

(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 `->`.
sourceraw docstring

map-keys->>cljmacro

(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 `->>`.
sourceraw docstring

map-vals->cljmacro

(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 `->`.
sourceraw docstring

map-vals->>cljmacro

(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 `->>`.
sourceraw docstring

not->cljmacro

(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 `->`.
sourceraw docstring

not->>cljmacro

(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 `->>`.
sourceraw docstring

or->cljmacro

(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 `->`.
sourceraw docstring

or->>cljmacro

(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 `->>`.
sourceraw docstring

pp->cljmacro

(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`.
sourceraw docstring

pp->>cljmacro

(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`.
sourceraw docstring

tapcljmacro

(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
sourceraw docstring

tap->cljmacro

(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 `->`.
sourceraw docstring

tap->>cljmacro

(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 `->>`.
sourceraw docstring

when->cljmacro

(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 `->`.
sourceraw docstring

when->>cljmacro

(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 `->>`.
sourceraw docstring

when-not->cljmacro

(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 `->`.
sourceraw docstring

when-not->>cljmacro

(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 `->>`.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close