Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you accept a callback argument, you can just call it inside the <code>doseq</code>:</p> <pre><code>(defmulti scan [f table &amp; args] (mapv class args)) ; mapv returns vector (defmethod scan [String String] [f table start-key end-key] ; ^- java.lang classes are imported implicitly (let [scan ... scanner ...] ; no need for two separate lets (doseq [result scanner] ; call f here, e.g. (f result)))) </code></pre> <p>Here <code>f</code> will be called once per result. Its return value, as well as the result itself, will be discarded immediately. You can of course call <code>f</code> with some preprocessed version of <code>result</code>, e.g. <code>(f (foo result) (bar result))</code>.</p> <p>You could also return a sequence / vector of results to the client and let it do its own processing. If the sequence is lazy, you need to make sure that any resources backing it stay open for the duration of the processing (and presumably that they are closed later -- see <code>with-open</code>; the processing code would need to execute inside the <code>with-open</code> and be done with the processing when it returns).</p> <p>For example, to return a vector of preprocessed results to the client you could do</p> <pre><code>(defmethod scan ... (let [...] (mapv (fn preprocess-result [result] (result-&gt;map result)) scanner))) </code></pre> <p>The client can then do whatever it wants with them. Use <code>map</code> to return a lazy sequence instead. If the client then needs to open/close a resource, you could accept it as an argument to scan, so that the client could say</p> <pre><code>(with-open [r (some-resource)] ; or mapv, dorun+map, doall+for, ... (doseq [result (scan r ...)] (do-stuff-with result))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload