PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/example/vars/doc-1217.html

https://github.com/mmcgrana/clj-doc
HTML | 33 lines | 33 code | 0 blank | 0 comment | 0 complexity | 68e073f1e6f8b407e8513916c33706b6 MD5 | raw file
  1. <div class="doc-item" id="doc-1217"><h2 class="doc-item-name">join<span class="namespace">(clojure.set)</span></h2><ul class="var-arglists"><li>(<span class="var-name">join</span> xrel yrel)</li><li>(<span class="var-name">join</span> xrel yrel km)</li></ul><div class="var-docstring"><p>When passed 2 rels, returns the rel corresponding to the natural
  2. join. When passed an additional keymap, joins on the corresponding
  3. keys.</p></div><div class="var-source"><pre>; set.clj:99
  4. (defn join
  5. ([xrel yrel] ;natural join
  6. (if (and (seq xrel) (seq yrel))
  7. (let [ks (intersection (set (keys (first xrel))) (set (keys (first yrel))))
  8. [r s] (if (&lt;= (count xrel) (count yrel))
  9. [xrel yrel]
  10. [yrel xrel])
  11. idx (index r ks)]
  12. (reduce (fn [ret x]
  13. (let [found (idx (select-keys x ks))]
  14. (if found
  15. (reduce #(conj %1 (merge %2 x)) ret found)
  16. ret)))
  17. #{} s))
  18. #{}))
  19. ([xrel yrel km] ;arbitrary key mapping
  20. (let [[r s k] (if (&lt;= (count xrel) (count yrel))
  21. [xrel yrel (map-invert km)]
  22. [yrel xrel km])
  23. idx (index r (vals k))]
  24. (reduce (fn [ret x]
  25. (let [found (idx (rename-keys (select-keys x (keys k)) k))]
  26. (if found
  27. (reduce #(conj %1 (merge %2 x)) ret found)
  28. ret)))
  29. #{} s))))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
  30. epl-v10.html at the root of this distribution. By using this software
  31. in any fashion, you are agreeing to be bound by the terms of this
  32. license. You must not remove this notice, or any other, from this
  33. software.</p></div></div>