-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
realize.clj
42 lines (35 loc) · 1.19 KB
/
realize.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns toucan2.realize
(:require
[potemkin :as p]
[toucan2.log :as log]
[toucan2.util :as u]))
(set! *warn-on-reflection* true)
;;;; TODO -- this should probably be moved to [[toucan2.protocols]], and be renamed `IRealize` for consistency.
(p/defprotocol+ Realize
(realize [x]
"Fully realize either a reducible query, or a result row from that query."))
(defn- realize-IReduceInit [this]
(log/tracef "realize IReduceInit %s" (symbol (.getCanonicalName (class this))))
(u/try-with-error-context ["realize IReduceInit" {::reducible this}]
(into []
(map (fn [row]
(log/tracef "realize row ^%s %s" (some-> row class .getCanonicalName symbol) row)
(u/try-with-error-context ["realize row" {::row row}]
(realize row))))
this)))
(extend-protocol Realize
Object
(realize [this]
(log/tracef "Already realized: %s" (class this))
this)
;; Eduction is assumed to be for query results.
;; TODO -- isn't an Eduction an IReduceInit??
clojure.core.Eduction
(realize [this]
(into [] (map realize) this))
clojure.lang.IReduceInit
(realize [this]
(realize-IReduceInit this))
nil
(realize [_]
nil))