Skip to content

Commit bcbadd3

Browse files
author
Rob Levy
committed
improved functionality for working with PyObjectDerived iterators
1 parent e79d1a4 commit bcbadd3

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject clojure-python "0.0.3"
1+
(defproject clojure-python "0.0.4"
22
:description "Improve seamlessness of Clojure Jython interop."
33
:dependencies [[org.clojure/clojure "1.1.0"]
44
[org.python/jython "2.5.1"]]

src/clojure_python/core.clj

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,25 @@
7777

7878
(defn dir
7979
"it's slightly nicer to call the dir method in this way"
80-
[x]
81-
(seq (.__dir__ x)))
80+
[x] (seq (.__dir__ x)))
81+
82+
(defn pyobj-nth
83+
"nth item in a 'PyObjectDerived'"
84+
[o i] (.__getitem__ o i))
8285

8386
(defn pyobj-range
84-
"Access PyObjDerived items by range"
85-
[o start end]
86-
(for [i (range start end)]
87-
(str (.__getitem__ o i))))
87+
"access 'PyObjectDerived' items as non-lazy range"
88+
[o start end] (for [i (range start end)] (pyobj-nth o i)))
8889

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))))
90+
(defn pyobj-iterate
91+
"access 'PyObjectDerived' items as Lazy Seq"
92+
[pyobj] (lazy-seq (.__iter__ pyobj)))
9993

10094
(defn java2py
101-
"to wrap java objects for input as jython, and unwrap jython output as java
102-
(thanks to Marc Downie on Clojure list for suggesting this)"[args]
95+
"to wrap java objects for input as jython, and unwrap
96+
Jython output as java (thanks to Marc Downie on Clojure
97+
list for suggesting this)"
98+
[args]
10399
(into-array
104100
org.python.core.PyObject
105101
(map

0 commit comments

Comments
 (0)