From 983549f185753891c302cd3c2ea9933ea2483884 Mon Sep 17 00:00:00 2001
From: Jim Blomo <jim.blomo+github@gmail.com>
Date: Mon, 28 May 2012 17:51:27 -0700
Subject: [PATCH] CLJ-1004 ArrayChunk implements Seqable

---
 .gitignore                           |    1 +
 src/clj/clojure/gvec.clj             |    6 ++++++
 src/jvm/clojure/lang/ArrayChunk.java |    9 ++++++++-
 test/clojure/test_clojure/chunk.clj  |   24 ++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 1 deletions(-)
 create mode 100644 test/clojure/test_clojure/chunk.clj

diff --git a/.gitignore b/.gitignore
index 7383fdb..ba97156 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 *.jar
+*.sw[po]
 target
 clojure.iws
 clojure.ipr
diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj
index 6aabd1e..f1193b2 100644
--- a/src/clj/clojure/gvec.clj
+++ b/src/clj/clojure/gvec.clj
@@ -49,6 +49,12 @@
       (if (< i end)
         (recur (f ret (.aget am arr i)) (inc i))
         ret)))
+
+  clojure.lang.Seqable
+  (seq [t]
+    (->> arr
+      (drop off)
+      (take (.count t))))
   )
 
 (deftype VecSeq [^clojure.core.ArrayManager am ^clojure.core.IVecImpl vec anode ^int i ^int offset] 
diff --git a/src/jvm/clojure/lang/ArrayChunk.java b/src/jvm/clojure/lang/ArrayChunk.java
index 9743083..e0dea50 100644
--- a/src/jvm/clojure/lang/ArrayChunk.java
+++ b/src/jvm/clojure/lang/ArrayChunk.java
@@ -13,8 +13,11 @@
 package clojure.lang;
 
 import java.io.Serializable;
+import java.util.Arrays;
 
-public final class ArrayChunk implements IChunk, Serializable {
+import clojure.lang.ArraySeq;
+
+public final class ArrayChunk implements IChunk, Serializable, Seqable {
 
 final Object[] array;
 final int off;
@@ -66,4 +69,8 @@ public Object reduce(IFn f, Object start) {
 			}
 		return ret;
 }
+
+public ISeq seq() {
+	return ArraySeq.createFromObject(Arrays.copyOfRange(array, off, end));
+}
 }
diff --git a/test/clojure/test_clojure/chunk.clj b/test/clojure/test_clojure/chunk.clj
new file mode 100644
index 0000000..0bc48d4
--- /dev/null
+++ b/test/clojure/test_clojure/chunk.clj
@@ -0,0 +1,24 @@
+;   Copyright (c) Rich Hickey. All rights reserved.
+;   The use and distribution terms for this software are covered by the
+;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;   which can be found in the file epl-v10.html at the root of this distribution.
+;   By using this software in any fashion, you are agreeing to be bound by
+;   the terms of this license.
+;   You must not remove this notice, or any other, from this software.
+
+; Author: Jim Blomo
+
+
+(ns clojure.test-clojure.chunk
+  (:use clojure.test))
+
+(deftest chunks-can-seq
+  (let [ov [1 2 3]
+        pv (vector-of :int 1 2 3)]
+
+    (is (= '(1 2 3) (seq (chunk-first (seq ov))))
+        "Object vector chunks are seqable")
+
+    (is (= '(1 2 3) (seq (chunk-first (seq pv))))
+        "Primitive vector chunks are seqable")))
+
-- 
1.7.1

