Skip to content

Commit

Permalink
[pipeline] Use conj! as the default pipeline rf
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yakushev committed Jan 5, 2025
1 parent b412026 commit 08af6fc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/toucan2/pipeline.clj
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@
"The default reducing function for all query types unless otherwise specified. Returns realized maps (by default, Toucan
2 instances)."
[_query-type]
((map realize/realize) conj))
(fn
([] (transient []))
([acc] (persistent! acc))
([acc x] (conj! acc (realize/realize x)))))

(defn ^:no-doc first-result-xform-fn
"Return a transducer that transforms a reducing function `rf` so it always takes at most one value and returns the first
Expand All @@ -370,7 +373,13 @@
(if (isa? query-type :toucan.result-type/update-count)
identity
(fn [rf]
(completing ((take 1) rf) first))))
(fn first-result-rf
([] ::nothing)
([acc] (when-not (= acc ::nothing)
(first (rf acc))))
([acc x] (if (= acc ::nothing)
(rf (rf) x)
acc))))))

;;;; Helper functions for implementing stuff like [[toucan2.select/select]]

Expand Down

0 comments on commit 08af6fc

Please sign in to comment.