Common sorted list: Difference between revisions
Content added Content deleted
(Add clojure solution) |
(→{{header|Clojure}}: Add point-free version) |
||
Line 439: | Line 439: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
===Efficient transducer & sorted-set version=== |
|||
<syntaxhighlight lang="lisp">(defn common-sorted [& colls] |
<syntaxhighlight lang="lisp">(defn common-sorted [& colls] |
||
(into (sorted-set) cat colls)) |
(into (sorted-set) cat colls)) |
||
Line 444: | Line 445: | ||
(common-sorted [5 1 3 8 9 4 8 7] [3 5 9 8 4] [1 3 7 9]) |
(common-sorted [5 1 3 8 9 4 8 7] [3 5 9 8 4] [1 3 7 9]) |
||
;; => #{1 3 4 5 7 8 9} |
;; => #{1 3 4 5 7 8 9} |
||
</syntaxhighlight> |
|||
===Point-free, list-based version=== |
|||
<syntaxhighlight lang="lisp">(def common-sorted (comp sort distinct concat)) |
|||
(common-sorted [5 1 3 8 9 4 8 7] [3 5 9 8 4] [1 3 7 9]) |
|||
;; => (1 3 4 5 7 8 9) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||