fix x/for (had a dirty repl, my bad) and put an example in the README.
This commit is contained in:
parent
24a11ea7e2
commit
8fb512b83a
2 changed files with 10 additions and 2 deletions
10
README.md
10
README.md
|
|
@ -14,7 +14,6 @@ Add this dependency to your project:
|
||||||
[net.cgrand/xforms "0.1.0-SNAPSHOT"]
|
[net.cgrand/xforms "0.1.0-SNAPSHOT"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
=> (require '[net.cgrand.xforms :as x])
|
=> (require '[net.cgrand.xforms :as x])
|
||||||
```
|
```
|
||||||
|
|
@ -28,6 +27,15 @@ Add this dependency to your project:
|
||||||
Execution time mean : 11,609631 µs
|
Execution time mean : 11,609631 µs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`for` is the transducing cousin of `clojure.core/for`:
|
||||||
|
|
||||||
|
```clj
|
||||||
|
=> (quick-bench (reduce + (for [i (range 128) j (range i)] (* i j))))
|
||||||
|
Execution time mean : 514,932029 µs
|
||||||
|
=> (quick-bench (transduce (x/for [i % j (range i)] (* i j)) + 0 (range 128)))
|
||||||
|
Execution time mean : 373,814060 µs
|
||||||
|
```
|
||||||
|
|
||||||
`by-key` and `reduce` are two new transducers. Here is an example usage:
|
`by-key` and `reduce` are two new transducers. Here is an example usage:
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
:let `(let ~expr ~body)
|
:let `(let ~expr ~body)
|
||||||
:when `(if ~expr ~body ~acc)
|
:when `(if ~expr ~body ~acc)
|
||||||
:while `(if ~expr ~body (reduced ~acc))
|
:while `(if ~expr ~body (reduced ~acc))
|
||||||
`(reduce (fn [~acc ~binding] ~body) ~acc ~expr)))
|
`(clj/reduce (fn [~acc ~binding] ~body) ~acc ~expr)))
|
||||||
`(~rf ~acc ~body)
|
`(~rf ~acc ~body)
|
||||||
(clj/partition 2 (rseq (vec seq-exprs))))]
|
(clj/partition 2 (rseq (vec seq-exprs))))]
|
||||||
`(fn [~rf]
|
`(fn [~rf]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue