io.jesi.backpack.macros

assoc-nx

macro

(assoc-nx m k v)(assoc-nx m k v & kvs)(assoc-nx m kvs)

Lazily assocs each kv if its key doesn’t already exist. Macro version of taoensso.encore/assoc-nx

assoc-nx!

macro

(assoc-nx! a k v)

Lazily atom/assoc! if the key does not already exist. Returns the value in the atom

catch->

macro

(catch-> handle & body)

catch->identity

macro

(catch->identity & body)

Wraps the body in a catch block, returning the result of the body or any thrown exception

catch->nil

macro

(catch->nil & body)

Wraps the body in a catch block, returning all thrown exceptions as nil

condf

macro

(condf v & clauses)

Takes a value, and a set of binary predicate clauses. For each clause (clause v) is evaluated. If it returns logical true, the clause is a match and the result-expr is returned. A single default expression can follow the clauses, and its value will be returned if no clause matches.

(condf {:map 1}
  map? "map"
  string? "string"
  nil)

def-

macro

(def- symbol)(def- symbol init)(def- symbol doc-string init)

Creates and interns a private var with the name of symbol in the current namespace (*ns*) or locates such a var if it already exists. If init is supplied, it is evaluated, and the root binding of the var is set to the resulting value. If init is not supplied, the root binding of the var is unaffected.

defconsts

macro

(defconsts body-fn & symbols)

Defines a collection of string constant values as individual symbols transforming their values using body-fn.

defkw

macro

(defkw kw)

Defines a symbol as the name of the given keyword in the current namespace

import-vars

macro

(import-vars & imports)

Imports a all symbols (including various metadata) from one namespace into the current namespace. Supports Clojure and ClojureScript. Similar to https://github.com/ztellman/potemkin

(import-vars
  [io.jesi.backpack.collection
   io.jesi.backpack.fn
   ...])

macro?

(macro? sym)

True if the provided sym is a macro

ns-of

macro

(ns-of sym)

Gets the namespace (as string) of the provided symbol

reify-ifn

macro

(reify-ifn invoke-fn & more)

Defines IFn invoke implementations to call as (invoke-fn this [args]). Note: Protocols do not support var args

setup-let

macro

(setup-let bindings & body)

Macro that allows local bindings (let block) to be reused. Use with-let to specify the binding scope.

(setup-let [x (rand-int 10)] [(with-let x) (with-let x)]) ;returns two random integers

shorthand

macro

(shorthand & symbols)

Returns a map with the keywords from the symbol names

shorthand*

(shorthand* keyfn symbols)

shorthand-assoc

macro

(shorthand-assoc map sym)(shorthand-assoc map sym & more)

shorthand-str

macro

(shorthand-str & symbols)

String shorthand. Returns a map with string keys from the symbol names

try*

macro

(try* & body)

Macro to catch multiple exceptions within a single body

(try*
  (condp = x
    0 (throw (Exception. "Exception"))
    1 (throw (RuntimeException. "Runtime"))
    3 (throw (ArithmeticException. "Arithmetic"))
    "Not Caught")
  (catch ArithmeticException _ "ArithmeticException")
  (catch-any [RuntimeException SecurityException] _ "Multi")
  (catch Exception _ "Exception"))))

when-debug

macro

(when-debug & body)

when-not=

macro

(when-not= test body)

with-let

(with-let & body)

with-open

macro

(with-open bindings & body)

bindings => [sym init …]

Evaluates body in a try expression with symbols bound to the values of the inits, and a finally clause that calls (bp/close sym) on each sym in reverse order.

with-open->

macro

(with-open-> x & forms)