Back
reducer (clj)
(source)function
(reducer coll xf)
Given a reducible collection, and a transformation function xf,
returns a reducible collection, where any supplied reducing
fn will be transformed by xf. xf is a function of reducing fn to
reducing fn.
Examples
clojure
(ns clojure.test-clojure.reducers
(:require [clojure.core.reducers :as r]
[clojure.test.generative :refer (defspec)]
[clojure.data.generators :as gen])
(:use clojure.test))
(defmacro defequivtest
;; f is the core fn, r is the reducers equivalent, rt is the reducible ->
;; coll transformer
[name [f r rt] fns]
`(deftest ~name
(let [c# (range -100 1000)]
(doseq [fn# ~fns]
(is (= (~f fn# c#)
(~rt (~r fn# c#))))))))
jonase/eastwood
(ns testcases.unusednss3
(:require [clojure.core.protocols :as protocols]
[clojure.core.reducers :as reducers]
[clojure.data :as data]
[clojure.java.io :as io]
[clojure.reflect :as reflect]))
(extend-protocol reducers/CollFold
String
(coll-fold [coll n combinef reducef] nil))
dco-dev/interval-tree
(ns com.dean.interval-tree.tree.interval-set
(:require [clojure.core.reducers :as r :refer [coll-fold]]
[clojure.set]
[com.dean.interval-tree.tree.interval :as interval]
[com.dean.interval-tree.tree.node :as node]
[com.dean.interval-tree.tree.order :as order]
[com.dean.interval-tree.tree.protocol :as proto]
[com.dean.interval-tree.tree.root]
[com.dean.interval-tree.tree.tree :as tree])
(:import [clojure.lang RT]
[com.dean.interval_tree.tree.protocol PExtensibleSet]
[com.dean.interval_tree.tree.root INodeCollection
IBalancedCollection
IOrderedCollection
IIntervalCollection]))
clojure.core.reducers.CollFold
(coll-fold [this n combinef reducef]
(with-interval-set this
(tree/node-chunked-fold n root combinef
(fn [acc node] (reducef acc (node/-k node)))))))
dco-dev/interval-tree
(ns com.dean.interval-tree.tree.ordered-set
(:require [clojure.core.reducers :as r :refer [coll-fold]]
[clojure.set]
[com.dean.interval-tree.tree.node :as node]
[com.dean.interval-tree.tree.order :as order]
[com.dean.interval-tree.tree.protocol :as proto]
[com.dean.interval-tree.tree.root]
[com.dean.interval-tree.tree.tree :as tree])
(:import [clojure.lang RT]
[com.dean.interval_tree.tree.protocol PExtensibleSet]
[com.dean.interval_tree.tree.root INodeCollection
IBalancedCollection
IOrderedCollection]))
clojure.core.reducers.CollFold
(coll-fold [this n combinef reducef]
(with-ordered-set this
(tree/node-chunked-fold n root combinef
(fn [acc node] (reducef acc (node/-k node)))))))
denno-clojure/mascarpone
(require '[clojure.core.reducers :as r])
; simple usage of reducers
(reduce + (r/filter even? (r/map inc [1 1 1 2])))
denno-clojure/mascarpone
(require '[clojure.core.reducers :as r])
(r/map inc [1 1 1 2])
; => #<reducers$folder$reify__6531 clojure.core.reducers$folder$reify__6531@dd4fe75>