specter/com.rpl.specter.macros.html

72 lines
18 KiB
HTML
Raw Normal View History

2016-06-02 16:03:15 +00:00
<!DOCTYPE html PUBLIC ""
"">
2016-06-08 11:00:50 +00:00
<html><head><meta charset="UTF-8" /><link href="css/default.css" rel="stylesheet" type="text/css" /><script src="js/jquery.min.js" type="text/javascript"></script><script src="js/page_effects.js" type="text/javascript"></script><title>com.rpl.specter.macros documentation</title></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Specter</span> <span class="project-version">0.11.1</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>com</span></div></div></li><li class="depth-2"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>rpl</span></div></div></li><li class="depth-3"><a href="com.rpl.specter.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>specter</span></div></a></li><li class="depth-4 branch current"><a href="com.rpl.specter.macros.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>macros</span></div></a></li><li class="depth-4 branch"><a href="com.rpl.specter.protocols.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>protocols</span></div></a></li><li class="depth-4 branch"><a href="com.rpl.specter.transient.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>transient</span></div></a></li><li class="depth-4"><a href="com.rpl.specter.zipper.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>zipper</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="com.rpl.specter.macros.html#var-declarepath"><div class="inner"><span>declarepath</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-defcollector"><div class="inner"><span>defcollector</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-defnav"><div class="inner"><span>defnav</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-defnavconstructor"><div class="inner"><span>defnavconstructor</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-defpathedfn"><div class="inner"><span>defpathedfn</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-defprotocolpath"><div class="inner"><span>defprotocolpath</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-extend-protocolpath"><div class="inner"><span>extend-protocolpath</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-fixed-pathed-nav"><div class="inner"><span>fixed-pathed-nav</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-nav"><div class="inner"><span>nav</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-paramscollector"><div class="inner"><span>paramscollector</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-paramsfn"><div class="inner"><span>paramsfn</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-path"><div class="inner"><span>path</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-pathed-collector"><div class="inner"><span>pathed-collector</span></div></a></li><li class="depth-1"><a href="com.rpl.specter.macros.html#var-providepath"><div class="inner"><span>providepa
as input. This macro is generally used in conjunction with [[fixed-pathed-nav]]
or [[variable-pathed-nav]]. When inline factoring is applied to a path containing
one of these higher order navigators, it will automatically interepret all
arguments as paths, factor them accordingly, and set up the callsite to
provide the parameters dynamically. Use ^:notpath metadata on arguments
to indicate non-path arguments that should not be factored  note that in order
to be inline factorable, these arguments must be statically resolvable (e.g. a
top level var). See `transformed` for an example.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L360">view source</a></div></div><div class="public anchor" id="var-defprotocolpath"><h3>defprotocolpath</h3><h4 class="type">macro</h4><div class="usage"><code>(defprotocolpath name)</code><code>(defprotocolpath name params)</code></div><div class="doc"><pre class="plaintext">Defines a navigator that chooses the path to take based on the type
of the value at the current point. May be specified with parameters to
specify that all extensions must require that number of parameters.
Currently not available for ClojureScript.
Example of usage:
(defrecord SingleAccount [funds])
(defrecord FamilyAccount [single-accounts])
(defprotocolpath FundsPath)
(extend-protocolpath FundsPath
SingleAccount :funds
FamilyAccount [ALL FundsPath]
)
</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L212">view source</a></div></div><div class="public anchor" id="var-extend-protocolpath"><h3>extend-protocolpath</h3><h4 class="type">macro</h4><div class="usage"><code>(extend-protocolpath protpath &amp; extensions)</code></div><div class="doc"><pre class="plaintext">Used in conjunction with `defprotocolpath`. See [[defprotocolpath]].
</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L329">view source</a></div></div><div class="public anchor" id="var-fixed-pathed-nav"><h3>fixed-pathed-nav</h3><h4 class="type">macro</h4><div class="usage"><code>(fixed-pathed-nav bindings impl1 impl2)</code></div><div class="doc"><pre class="plaintext">This helper is used to define navigators that take in a fixed number of other
2016-06-02 16:03:15 +00:00
paths as input. Those paths may require late-bound params, so this helper
will create a parameterized navigator if that is the case. If no late-bound params
2016-06-08 11:00:50 +00:00
are required, then the result is executable.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L155">view source</a></div></div><div class="public anchor" id="var-nav"><h3>nav</h3><h4 class="type">macro</h4><div class="usage"><code>(nav params impl1 impl2)</code></div><div class="doc"><pre class="plaintext">Defines a navigator with late bound parameters. This navigator can be precompiled
2016-06-02 16:03:15 +00:00
with other navigators without knowing the parameters. When precompiled with other
navigators, the resulting path takes in parameters for all navigators in the path
2016-06-08 11:00:50 +00:00
that needed parameters (in the order in which they were declared).</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L115">view source</a></div></div><div class="public anchor" id="var-paramscollector"><h3>paramscollector</h3><h4 class="type">macro</h4><div class="usage"><code>(paramscollector params impl)</code></div><div class="doc"><pre class="plaintext">Defines a Collector with late bound parameters. This collector can be precompiled
2016-06-02 16:03:15 +00:00
with other selectors without knowing the parameters. When precompiled with other
selectors, the resulting selector takes in parameters for all selectors in the path
that needed parameters (in the order in which they were declared).
2016-06-08 11:00:50 +00:00
</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L137">view source</a></div></div><div class="public anchor" id="var-paramsfn"><h3>paramsfn</h3><h4 class="type">macro</h4><div class="usage"><code>(paramsfn params [structure-sym] &amp; impl)</code></div><div class="doc"><pre class="plaintext"></pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L126">view source</a></div></div><div class="public anchor" id="var-path"><h3>path</h3><h4 class="type">macro</h4><div class="usage"><code>(path &amp; path)</code></div><div class="doc"><pre class="plaintext">Same as calling comp-paths, except it caches the composition of the static part
2016-06-02 16:03:15 +00:00
of the path for later re-use (when possible). For almost all idiomatic uses
of Specter provides huge speedup. This macro is automatically used by the
2016-06-08 11:00:50 +00:00
select/transform/setval/replace-in/etc. macros.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L447">view source</a></div></div><div class="public anchor" id="var-pathed-collector"><h3>pathed-collector</h3><h4 class="type">macro</h4><div class="usage"><code>(pathed-collector [name path] impl)</code></div><div class="doc"><pre class="plaintext">This helper is used to define collectors that take in a single selector
2016-06-02 16:03:15 +00:00
paths as input. That path may require late-bound params, so this helper
will create a parameterized selector if that is the case. If no late-bound params
2016-06-08 11:00:50 +00:00
are required, then the result is executable.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L191">view source</a></div></div><div class="public anchor" id="var-providepath"><h3>providepath</h3><h4 class="type">macro</h4><div class="usage"><code>(providepath name apath)</code></div><div class="doc"><pre class="plaintext"></pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L316">view source</a></div></div><div class="public anchor" id="var-replace-in"><h3>replace-in</h3><h4 class="type">macro</h4><div class="usage"><code>(replace-in apath transform-fn structure &amp; args)</code></div><div class="doc"><pre class="plaintext">Similar to transform, except returns a pair of [transformed-structure sequence-of-user-ret].
The transform-fn in this case is expected to return [ret user-ret]. ret is
what's used to transform the data structure, while user-ret will be added to the user-ret sequence
in the final return. replace-in is useful for situations where you need to know the specific values
of what was transformed in the data structure.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation it it's not possible to
factor/cache the path.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L576">view source</a></div></div><div class="public anchor" id="var-select"><h3>select</h3><h4 class="type">macro</h4><div class="usage"><code>(select apath structure)</code></div><div class="doc"><pre class="plaintext">Navigates to and returns a sequence of all the elements specified by the path.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation it it's not possible to
factor/cache the path.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L527">view source</a></div></div><div class="public anchor" id="var-select-first"><h3>select-first</h3><h4 class="type">macro</h4><div class="usage"><code>(select-first apath structure)</code></div><div class="doc"><pre class="plaintext">Returns first element found. Not any more efficient than select, just a convenience.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation it it's not possible to
factor/cache the path.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L551">view source</a></div></div><div class="public anchor" id="var-select-one"><h3>select-one</h3><h4 class="type">macro</h4><div class="usage"><code>(select-one apath structure)</code></div><div class="doc"><pre class="plaintext">Like select, but returns either one element or nil. Throws exception if multiple elements found.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation it it's not possible to
factor/cache the path.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L543">view source</a></div></div><div class="public anchor" id="var-select-one.21"><h3>select-one!</h3><h4 class="type">macro</h4><div class="usage"><code>(select-one! apath structure)</code></div><div class="doc"><pre class="plaintext">Returns exactly one element, throws exception if zero or multiple elements found.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation it it's not possible to
factor/cache the path.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L535">view source</a></div></div><div class="public anchor" id="var-setval"><h3>setval</h3><h4 class="type">macro</h4><div class="usage"><code>(setval apath aval structure)</code></div><div class="doc"><pre class="plaintext">Navigates to each value specified by the path and replaces it by `aval`.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation it it's not possible to
factor/cache the path.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L568">view source</a></div></div><div class="public anchor" id="var-transform"><h3>transform</h3><h4 class="type">macro</h4><div class="usage"><code>(transform apath transform-fn structure)</code></div><div class="doc"><pre class="plaintext">Navigates to each value specified by the path and replaces it by the result of running
the transform-fn on it.
This macro will attempt to do inline factoring and caching of the path, falling
back to compiling the path on every invocation it it's not possible to
factor/cache the path.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L559">view source</a></div></div><div class="public anchor" id="var-variable-pathed-nav"><h3>variable-pathed-nav</h3><h4 class="type">macro</h4><div class="usage"><code>(variable-pathed-nav [latepaths-seq-sym paths-seq] impl1 impl2)</code></div><div class="doc"><pre class="plaintext">This helper is used to define navigators that take in a variable number of other
2016-06-02 16:03:15 +00:00
paths as input. Those paths may require late-bound params, so this helper
will create a parameterized navigator if that is the case. If no late-bound params
2016-06-08 11:00:50 +00:00
are required, then the result is executable.</pre></div><div class="src-link"><a href="https://github.com/nathanmarz/specter/tree/0.11.1/src/clj/com/rpl/specter/macros.clj#L174">view source</a></div></div></div></body></html>