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->`.
(derive-config m)
Replaces any ^:derived
values in m
.
Example:
(def m
{:first-name "John"
:last-name "Doe"
:full-name ^:derived #(str (get-config % :first-name) " "
(get-config % :last-name))})
(derive-config m)
=> {:first-name "John" :last-name "Doe" :full-name "John Doe"}
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.
get-config
is like get
, but if the return value is a :derived
function,
get-config
will derive it before returning. It should be used within
:derived
function as in the example
Replaces any `^:derived` values in `m`. Example: ``` (def m {:first-name "John" :last-name "Doe" :full-name ^:derived #(str (get-config % :first-name) " " (get-config % :last-name))}) (derive-config m) => {:first-name "John" :last-name "Doe" :full-name "John Doe"} ``` 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. `get-config` is like `get`, but if the return value is a `:derived` function, `get-config` will derive it before returning. It should be used within `:derived` function as in the example
(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.
(format-columns rows)
Formats rows of text into columns.
Example:
(doseq [row (format-columns [["hellooooooooo " "there"]
["foo " "bar"]
["one column"]])]
(println row))
hellooooooooo there
foo bar
one column
Formats rows of text into columns. Example: ``` (doseq [row (format-columns [["hellooooooooo " "there"] ["foo " "bar"] ["one column"]])] (println row)) hellooooooooo there foo bar one column ```
(get-config m k)
(get-config m k not-found)
See [derive-config].
See [derive-config].
(get-in-config m ks)
(get-in-config m ks not-found)
See [derive-config].
See [derive-config].
(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.
(maybe-slurp f)
Attempts to slurp f
, returning nil on failure
Attempts to slurp `f`, returning nil on failure
(print-table header-info table)
Prints a nicely formatted table.
Example:
(print-table
[[:foo "Foo"] [:bar "Bar"]]
[{:foo 1 :bar 2} {:foo 3 :bar 4}])
=> Foo Bar
1 2
3 4
Prints a nicely formatted table. Example: ``` (print-table [[:foo "Foo"] [:bar "Bar"]] [{:foo 1 :bar 2} {:foo 3 :bar 4}]) => Foo Bar 1 2 3 4 ```
(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. nil
s 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 ```
(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 is a website building & hosting documentation for Clojure/Script libraries
× close