Skip to content

Commit 6a3651a

Browse files
author
Rob Levy
committed
changed how PyObjDerived iterators are handled
1 parent 0ef59d3 commit 6a3651a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To include as a dependency:
2424

2525
Copy the config section found at http://clojars.org/clojure-python into your dependencies in your project's project.clj.
2626

27-
Important: it will be necessary to include step #2 above (mvn install...) and the 2.5.1 jar itself in any installation instructions for using this as a dependency, until a recent version Jython is made available in the central maven repository.
27+
Important: it will be necessary to include step #2 above (mvn install...) and the 2.5.1 jar itself in any installation instructions for using this as a dependency, until a recent version of Jython is made available in the central maven repository.
2828

2929
## License
3030

src/clojure_python/core.clj

+14-3
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,22 @@
8080
[x]
8181
(seq (.__dir__ x)))
8282

83-
(defn iter
84-
"Jython sometimes represents things as 'PyObjectDerived', which has no direct method to get their items as a seq"
83+
(defn pyobj-range
84+
"Access PyObjDerived items by range"
8585
[o start end]
8686
(for [i (range start end)]
87-
(.__getitem__ o i)))
87+
(str (.__getitem__ o i))))
88+
89+
(defn pyobj-iterate [pyobj]
90+
"Access 'PyObjectDerived' items as a Lazy Seq"
91+
(let [iter (.__iter__ pyobj)]
92+
(letfn
93+
[(do-iter [iter]
94+
(when (seq iter)
95+
(lazy-seq
96+
(cons (str (.__iternext__ iter))
97+
(do-iter iter)))))]
98+
(do-iter iter))))
8899

89100
(defn java2py
90101
"to wrap java objects for input as jython, and unwrap jython output as java

0 commit comments

Comments
 (0)