Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
use clj-tuple for returning multiple values from doreduce
Browse files Browse the repository at this point in the history
  • Loading branch information
ztellman committed Sep 21, 2013
1 parent 5cf686d commit 0e90cd2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Full documentation can be found [here](http://ideolalia.com/vertigo).

### usage

[![Build Status](https://travis-ci.org/ztellman/vertigo.png?branch=master)](https://travis-ci.org/ztellman/vertigo)

```clj
[vertigo "0.1.1"]
```
Expand Down
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:url "http://opensource.org/licenses/MIT"}
:dependencies [[potemkin "0.3.4-SNAPSHOT"]
[primitive-math "0.1.3"]
[clj-tuple "0.1.2"]
[byte-streams "0.1.5"]
[riddley "0.1.5-SNAPSHOT"]]
:profiles {:dev {:dependencies [[criterium "0.4.1"]
Expand Down
9 changes: 5 additions & 4 deletions src/vertigo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(:use
potemkin)
(:require
[clj-tuple :refer (tuple)]
[riddley.walk :as rd]
[byte-streams :as bytes]
[vertigo.structs :as s]
Expand Down Expand Up @@ -589,7 +590,7 @@
(and (seq? x) (= 'break (first x)))
(if (= 2 (count x))
(second x)
`(vector ~@(rest x)))
`(tuple ~@(rest x)))

(= 1 (count values))
`(recur (p/+ idx## ~step) ~x)
Expand All @@ -604,7 +605,7 @@
(rd/macroexpand-all `(do ~@body))))
~(if (= 1 (count values))
(:sym (first values))
`(vector ~@(map :sym values))))))))
`(tuple ~@(map :sym values))))))))

;; multi-dimensional iteration
(let [{:keys [seqs limits values iterators]} arguments
Expand All @@ -619,7 +620,7 @@
(and (seq? x) (= 'break (first x)))
(if (= 2 (count x))
(second x)
`(vector ~@(rest x)))
`(tuple ~@(rest x)))

(= 1 (count values))
`(recur ~@(map :sym iterators) ~x)
Expand Down Expand Up @@ -685,7 +686,7 @@
~body
~(if (= 1 (count values))
(:sym (first values))
`(vector ~@(map :sym values)))))))))))))
`(tuple ~@(map :sym values)))))))))))))

(defmacro doreduce
"A combination of `doseq` and `reduce`, this is a primitive for efficient batch operations over sequences.
Expand Down

0 comments on commit 0e90cd2

Please sign in to comment.