Liking cljdoc? Tell your friends :D

knitty.core

Core functionalities of the Knitty system.

Core functionalities of the Knitty system.
raw docstring

*registry*clj

source

*tracing*clj

source

declare-yarncljmacro

(declare-yarn nm)

Defines an abstract Yarn without an implementation. Useful for making forward declarations.

Defines an abstract Yarn without an implementation.
Useful for making forward declarations.
sourceraw docstring

defyarncljmacro

(defyarn name & doc-binds-body)

Defines a Yarn (a computation node in Knitty) and registers it in the global registry.

A Yarn is identified by a qualified keyword derived from the current namespace and the given name. This macro supports multiple forms and binding modes to declare dependencies and control evaluation.

(defyarn yarn-name) (defyarn yarn-name "documentation") (defyarn yarn-name {bind-name dep-yarn-name, ...} & body) (defyarn yarn-name "documentation" {bind-name dep-yarn-name, ...} & body)

In the optional dependency binding map, each binding can be annotated with meta flags that control how the dependency is resolved and bound to a local variable:

  • :sync Synchronous value; Knitty automatically awaits the dependent node if needed.
  • :defer Deferred, which will be resolved to the node value; no awaiting happens.
  • :lazy Delay-like object, which will return a deferred on deref; the dependent node computation starts after the first deref.
  • :case 1-arg function that dynamically routes to the specified yarn and returns a deferred.
  • :maybe Dependency as deferred, but does not start computation if its node; may never resolve (!!!) if no other nodes depend on it.

Metadata on the yarn name (or binding map) may also contain:

  • :spec Instructs 'defyarn' to automatically register the defined clojure-spec on ::yarn-key.
  • :fork Runs the node via FJP fork.
  • :reorder-deps Reorders yarn dependencies based on their definition order (default true).

Examples:

(defyarn ^{:spec number?} in-node "input node")

(defyarn node2 {} (println "compute node2") 0)

(defyarn work-node "yarn documentation" ^{:spec number? :fork true} { x in-node ^:defer y in-node ^:lazy z in-node ^:case f1 {1 in-node, 2 node2} ^:case f2 #{in-node, node2} ^:maybe m node2 } (assert (number? x)) (assert (kd/deferred? y)) (assert (kd/deferred? @z)) (assert (every? fn? [f1 f2])) (assert (kd/deferred? (f1 1))) (assert (kd/deferred? (f2 ::in-node))) (assert (kd/deferred? m)) ::ok )

@(yank {in-node 1} [work-node]) ;; => {::in-node 1, ::work-node ::ok}

Defines a Yarn (a computation node in Knitty) and registers it in the global registry.

A Yarn is identified by a qualified keyword derived from the current namespace and the given name.
This macro supports multiple forms and binding modes to declare dependencies and control evaluation.

  (defyarn yarn-name)
  (defyarn yarn-name "documentation")
  (defyarn yarn-name {bind-name dep-yarn-name, ...} & body)
  (defyarn yarn-name "documentation" {bind-name dep-yarn-name, ...} & body)

In the optional dependency binding map, each binding can be annotated with meta flags that control
how the dependency is resolved and bound to a local variable:
- `:sync`    Synchronous value; Knitty automatically awaits the dependent node if needed.
- `:defer`   Deferred, which will be resolved to the node value; no awaiting happens.
- `:lazy`    Delay-like object, which will return a deferred on deref; the dependent node computation starts after the first deref.
- `:case`    1-arg function that dynamically routes to the specified yarn and returns a deferred.
- `:maybe`   Dependency as deferred, but does not start computation if its node; may never resolve (!!!) if no other nodes depend on it.

Metadata on the yarn name (or binding map) may also contain:
- `:spec`           Instructs 'defyarn' to automatically register the defined clojure-spec on ::yarn-key.
- `:fork`           Runs the node via FJP fork.
- `:reorder-deps`   Reorders yarn dependencies based on their definition order (default true).

Examples:

  (defyarn ^{:spec number?} in-node "input node")

  (defyarn node2 {}
    (println "compute node2")
    0)

  (defyarn work-node
    "yarn documentation"
    ^{:spec number?
      :fork true}
    {        x in-node
     ^:defer y in-node
     ^:lazy  z in-node
     ^:case  f1 {1 in-node, 2 node2}
     ^:case  f2 #{in-node, node2}
     ^:maybe m node2
    }
    (assert (number? x))
    (assert (kd/deferred? y))
    (assert (kd/deferred? @z))
    (assert (every? fn? [f1 f2]))
    (assert (kd/deferred? (f1 1)))
    (assert (kd/deferred? (f2 ::in-node)))
    (assert (kd/deferred? m))
    ::ok
   )

  @(yank {in-node 1} [work-node])
  ;; => {::in-node 1, ::work-node ::ok}
sourceraw docstring

defyarn-methodcljmacro

(defyarn-method multiyarn-name dispatch-value bindings-vec & body)

Creates and installs a new method of multiyarn associated with dispatch-value.

Creates and installs a new method of multiyarn associated with dispatch-value.
sourceraw docstring

defyarn-multicljmacro

(defyarn-multi name docstring? dispatch-yarn & multi-options)

Defines a new multiyarn. Dispatching is routed by the value of dispatch-yarn' using same mechanics asdefmultimacro. Optional parameters are:hierarchyand:default`.

Defines a new multiyarn.  Dispatching is routed by the value of `dispatch-yarn'
using same mechanics as `defmulti` macro.  Optional parameters are `:hierarchy` and `:default`.
sourceraw docstring

enable-tracing!clj

(enable-tracing!)
(enable-tracing! enable)

Globally enables Knitty tracing.

Globally enables Knitty tracing.
sourceraw docstring

(link-yarn! yarn yarn-target)

Redeclares a Yarn as a symlink to the yarn-target.

Redeclares a Yarn as a symlink to the `yarn-target`.
sourceraw docstring

register-yarnclj

(register-yarn yarn)
(register-yarn yarn no-override)

Registers a Yarn into the global registry. Does nothing if the Yarn is already registered and the no-override flag is true.

Registers a Yarn into the global registry. Does nothing if the Yarn
is already registered and the `no-override` flag is true.
sourceraw docstring

set-executor!clj

(set-executor! executor)

Globally set knitty executor, returns old value.

Globally set knitty executor, returns old value.
sourceraw docstring

yankcljmacro

(yank inputs yarns)
(yank inputs yarns & {:as opts})

Computes and adds missing nodes to the 'inputs' map. Always returns a deferred.

Computes and adds missing nodes to the 'inputs' map. Always returns a deferred.
sourceraw docstring

yank*clj

(yank* inputs yarns)
(yank* inputs yarns opts)

Computes missing nodes. Always returns a deferred resolved to a YankResult. YankResult implements ILookup, Seqable, IObj, IKVReduce, IReduceInit.

Options are:

  • :executor An instance of java.util.concurrent.Executor used to run code.
  • :preload Preloads all values from the input map.
  • :bindings A flag indicating that thread-local bindings should be captured and installed for yarns.
  • :tracing A flag indicating whether to capture tracing (introduces some performance penalty).
  • :registry A Knitty registry with available yarns, useful for mocking code.
Computes missing nodes. Always returns a deferred resolved to a YankResult.
YankResult implements ILookup, Seqable, IObj, IKVReduce, IReduceInit.

Options are:
 - `:executor`  An instance of `java.util.concurrent.Executor` used to run code.
 - `:preload`   Preloads all values from the input map.
 - `:bindings`  A flag indicating that thread-local bindings should be captured and installed for yarns.
 - `:tracing`   A flag indicating whether to capture tracing (introduces some performance penalty).
 - `:registry`  A Knitty registry with available yarns, useful for mocking code.
sourceraw docstring

yank-error?clj

(yank-error? ex)

Returns true if the exception was rethrown by a yank function.

Returns true if the exception was rethrown by a `yank` function.
sourceraw docstring

yank1cljmacro

(yank1 inputs yarns)
(yank1 inputs yarn & {:as opts})

Computes and returns a single node. Intended to be used in REPL sessions where you need to retrieve just a single yarn value. Tracing is disabled; use the wrapped yank* if you need it.

Logically similar to:

(md/chain (yank inputs [::yarn-key]) ::yarn-key)

Computes and returns a single node.
Intended to be used in REPL sessions where you need to retrieve just a single yarn value.
Tracing is disabled; use the wrapped `yank*` if you need it.

Logically similar to:

  (md/chain (yank inputs [::yarn-key]) ::yarn-key)
sourceraw docstring

yarncljmacro

(yarn k & exprs)

Returns a Yarn object (without registering it into the global registry). May capture variables from the outer scope. Supports the same set of binding flags as defyarn (e.g., :defer, :lazy, :maybe, :case, :fork).

(defyarn input) @(yank {input 1} [(yarn ::output {x input} (+ x 1))]) ;; => {::input 1, ::output 2}

Returns a Yarn object (without registering it into the global registry).
May capture variables from the outer scope. Supports the same set of binding flags
as `defyarn` (e.g., :defer, :lazy, :maybe, :case, :fork).

  (defyarn input)
  @(yank
     {input 1}
     [(yarn ::output {x input} (+ x 1))])
  ;; => {::input 1, ::output 2}
sourceraw docstring

yarn-prefer-methodcljmacro

(yarn-prefer-method yarn-ref dispatch-val-x dispatch-val-y)

Causes the multiyarn to prefer matches of dispatch-val-x over dispatch-val-y.

Causes the multiyarn to prefer matches of `dispatch-val-x` over `dispatch-val-y`.
sourceraw docstring

yr->mapclj

(yr->map yr)

Converts the result of yank* into a persistent map.

Converts the result of `yank*` into a persistent map.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close