File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 2121 #? (:clj
2222 (:import [rethinkdb.core Connection])))
2323
24+ (defn func
25+ " Unsweetened alternative to fn. The fn macro has the benefit of
26+ providing a syntax that mirrors the native clojure fn, but
27+ oftentimes it's necessary to have the added versatility of a
28+ definition that accepts pure data.
29+
30+ Args is a vector of keywords. Terms is a term map.
31+ e.g. (func [::my-arg] terms)"
32+ [args terms]
33+ (term :FUNC [args terms]))
34+
2435#?(:clj (defmacro fn [args & [body]]
25- (let [new-args (into [] (clojure.core/map #(hash-map :temp-var (keyword %)) args))
36+ (let [new-args (into [] (clojure.core/map
37+ #(hash-map :temp-var (keyword %)) args))
2638 new-replacements (zipmap args new-args)
2739 new-terms (walk/postwalk-replace new-replacements body)]
28- (term :FUNC [ new-args new-terms] ))))
40+ (func new-args new-terms))))
2941
3042; ;; Import connect
3143
Original file line number Diff line number Diff line change 303303 x)))})))
304304 conn)))))
305305
306+ (deftest unsweetened-fns
307+ (with-open [conn (r/connect )]
308+ (is (= [{:a {:foo " bar" }
309+ :b [1 2 ]}]
310+ (r/run (-> [{:foo " bar" }]
311+ (r/map (r/func [::x ]
312+ {:a ::x
313+ :b (-> [1 2 ]
314+ (r/map (r/func [::x ] ::x )))})))
315+ conn)))
316+ (is (= [{:a {:foo " bar" }
317+ :b [{:foo " bar" } {:foo " bar" }]}]
318+ (r/run (-> [{:foo " bar" }]
319+ (r/map (r/func [::x ]
320+ {:a ::x
321+ :b (-> [1 2 ]
322+ (r/map (r/func [::y ] ::x )))})))
323+ conn)))))
324+
306325(deftest filter-with-default
307326 (with-open [conn (r/connect )]
308327 (let [twin-peaks [{:name " Cole" , :job " Regional Bureau Chief" }
You can’t perform that action at this time.
0 commit comments