Utility library. Docstrings are omitted for simple functions; read the source to see what they do.
Utility library. Docstrings are omitted for simple functions; read the source to see what they do.
(cljs-import-vars nspace & syms)Like potemkin/import-vars but supports importing cljs-only functions.
Example:
(cljs-import-vars my.namespace.core
foo bar baz)
Like `potemkin/import-vars` but supports importing cljs-only functions.
Example:
```
(cljs-import-vars my.namespace.core
foo bar baz)
```(condas-> expr name & clauses)Combination of cond-> and as->.
Combination of `cond->` and `as->`.
(defconfig default)Defines config and init-config! vars.
Example:
(defconfig
{:first-name "John"
:last-name "Doe"
:full-name ^:derived #(str (:first-name %) " " (:last-name %))})
config
=> {:first-name "John" :last-name "Doe" :full-name "John Doe"}
(init-config! {:first-name "Jane"})
config
=> {:first-name "Jane" :last-name "Doe" :full-name "Jane Doe"}
default is a map. Any values with a truthy :derived metadata value must
be single-argument functions. These functions will be replaced with their return
values, with the config map as the argument.
init-config! takes any number of maps and merges them onto the provided config
map using taoensso.encore/nested-merge, deriving values afterward.
Defines `config` and `init-config!` vars.
Example:
```
(defconfig
{:first-name "John"
:last-name "Doe"
:full-name ^:derived #(str (:first-name %) " " (:last-name %))})
config
=> {:first-name "John" :last-name "Doe" :full-name "John Doe"}
(init-config! {:first-name "Jane"})
config
=> {:first-name "Jane" :last-name "Doe" :full-name "Jane Doe"}
```
`default` is a map. Any values with a truthy `:derived` metadata value must
be single-argument functions. These functions will be replaced with their return
values, with the config map as the argument.
`init-config!` takes any number of maps and merges them onto the provided config
map using `taoensso.encore/nested-merge`, deriving values afterward.(derive-config m)Replaces any ^:derived values in m. See defconfig.
Replaces any `^:derived` values in `m`. See [[defconfig]].
(doclines _var)Returns the docstring of a var as a collection of lines, removing indentation.
Returns the docstring of a var as a collection of lines, removing indentation.
(inherit child-name [parent-instance :as fields] & overrides)Like deftype but with default function implementations.
The first field is the "parent": for any protocol functions you don't define, the function will be called again with the parent as the first argument instead of the current object.
Example:
(defprotocol P
(foo [this])
(bar [this]))
(deftype Parent []
P
(foo [_] "parent foo")
(bar [_] "parent bar"))
(inherit Child [parent]
P
(foo [_] "child foo"))
(def parent (Parent.))
(def child (Child. parent))
(foo child)
=> "child foo"
(bar child)
=> "parent bar"
Like `deftype` but with default function implementations. The first field is the "parent": for any protocol functions you don't define, the function will be called again with the parent as the first argument instead of the current object. Example: ``` (defprotocol P (foo [this]) (bar [this])) (deftype Parent [] P (foo [_] "parent foo") (bar [_] "parent bar")) (inherit Child [parent] P (foo [_] "child foo")) (def parent (Parent.)) (def child (Child. parent)) (foo child) => "child foo" (bar child) => "parent bar" ```
(js<! form)Like <! but for js promises. See to-chan.
Like `<!` but for js promises. See [[to-chan]].
(load-fns & forms)Defines a bunch of "dynamic functions" (see loadf).
Example:
(load-fns
foo my.lib/foo
bar my.lib/bar
baz your.lib/baz)
(foo) ; same as (do (require 'my.lib) (my.lib/foo))
Defines a bunch of "dynamic functions" (see [[loadf]]). Example: ``` (load-fns foo my.lib/foo bar my.lib/bar baz your.lib/baz) (foo) ; same as (do (require 'my.lib) (my.lib/foo)) ```
(load-var sym)Dynamically loads a var.
sym: a fully-qualified var symbol.
Dynamically loads a var. `sym`: a fully-qualified var symbol.
(loadf sym)Returns a function that dynamically loads and calls the specified function.
sym: a fully-qualified function symbol.
Returns a function that dynamically loads and calls the specified function. `sym`: a fully-qualified function symbol.
(text & forms)Generates a string from pairs of conditions and lines of text.
The right-hand side values will be flattened, so you can give strings,
collections of strings, or nested collections of strings. nils are
removed.
Example:
(println (text
true ["foo" nil "bar"]
false "baz"
true "quux"))
foo
bar
quux
Generates a string from pairs of conditions and lines of text.
The right-hand side values will be flattened, so you can give strings,
collections of strings, or nested collections of strings. `nil`s are
removed.
Example:
```
(println (text
true ["foo" nil "bar"]
false "baz"
true "quux"))
foo
bar
quux
```(text-columns rows)Formats rows of text into columns.
Example:
(doseq [row (text-columns [["hellooooooooo " "there"]
["foo " "bar"]])]
(println row))
hellooooooooo there
foo bar
Formats rows of text into columns.
Example:
```
(doseq [row (text-columns [["hellooooooooo " "there"]
["foo " "bar"]])]
(println row))
hellooooooooo there
foo bar
```(to-chan p)Converts a js promise to a channel. If the promise throws an error, logs to the console and closes the channel.
Converts a js promise to a channel. If the promise throws an error, logs to the console and closes the channel.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |