|
197 | 197 | (fn seq [o] |
198 | 198 | (basilisp.lang.runtime/to-seq o))) |
199 | 199 |
|
| 200 | +(def ^{:doc "Coerce the python Iterable ``it`` to a Seq. Supports both re-iterable |
| 201 | + (as with ``seq``) as well as single-use iterables that always return |
| 202 | + the same iterator." |
| 203 | + :arglists '([it])} |
| 204 | + iterator-seq |
| 205 | + (fn iterator-seq [it] |
| 206 | + (basilisp.lang.runtime/to-iterator-seq it))) |
| 207 | + |
| 208 | + |
200 | 209 | (def ^{:doc "Apply function ``f`` to the arguments provided. |
201 | 210 |
|
202 | 211 | The last argument must always be coercible to a Seq. Intermediate |
|
326 | 335 | (.alter-meta #'vector? assoc :inline ^:safe-py-params (fn [o] `(instance? basilisp.lang.interfaces/IPersistentVector ~o))) |
327 | 336 | (.alter-meta #'seq? assoc :inline ^:safe-py-params (fn [o] `(instance? basilisp.lang.interfaces/ISeq ~o))) |
328 | 337 | (.alter-meta #'seq assoc :inline ^:safe-py-params (fn [o] `(basilisp.lang.runtime/to-seq ~o))) |
| 338 | +(.alter-meta #'iterator-seq assoc :inline ^:safe-py-params (fn [it] `(basilisp.lang.runtime/to-iterator-seq ~it))) |
329 | 339 | (.alter-meta #'set assoc :inline ^:safe-py-params (fn [coll] `(basilisp.lang.runtime/to-set ~coll))) |
330 | 340 | (.alter-meta #'vec assoc :inline ^:safe-py-params (fn [coll] `(basilisp.lang.runtime/vector ~coll))) |
331 | 341 |
|
|
1484 | 1494 | (instance? basilisp.lang.interfaces/IReversible x)) |
1485 | 1495 |
|
1486 | 1496 | (defn ^:inline seqable? |
1487 | | - "Return ``true`` if an :py:class:`basilisp.lang.interfaces.ISeq` can be produced from |
1488 | | - ``x``\\." |
| 1497 | + "Return ``true`` if :lpy:fn:``seq`` is supported on``x``\\." |
1489 | 1498 | [x] |
1490 | | - (instance? basilisp.lang.interfaces/ISeqable x)) |
| 1499 | + (or (instance? basilisp.lang.interfaces/ISeqable x) |
| 1500 | + (basilisp.lang.runtime/is-reiterable-iterable x))) |
1491 | 1501 |
|
1492 | 1502 | (defn ^:inline sequential? |
1493 | 1503 | "Return ``true`` if ``x`` implements :py:class:`basilisp.lang.interfaces.ISequential`\\." |
|
2514 | 2524 | "Return a lazy sequence of the concatenation of ``colls``\\. None of the input |
2515 | 2525 | collections will be evaluated until it is needed." |
2516 | 2526 | [& colls] |
2517 | | - `(concat ~@(map (fn [coll] `(lazy-seq ~coll)) colls))) |
| 2527 | + `(concat ~@(iterator-seq (python/map (fn [coll] `(lazy-seq ~coll)) colls)))) |
| 2528 | + |
2518 | 2529 |
|
2519 | 2530 | (defn dorun |
2520 | 2531 | "Force a lazy sequence be fully realized. Returns ``nil``\\. |
|
3259 | 3270 | sequence." |
3260 | 3271 | [v] |
3261 | 3272 | (lazy-seq |
3262 | | - (when (and (or (seq? v) (seqable? v)) (seq v)) |
| 3273 | + (when (and (sequential? v) (seq v)) |
3263 | 3274 | (let [e (first v) |
3264 | 3275 | r (rest v)] |
3265 | 3276 | (if (or (seq? e) (seqable? e)) |
|
4570 | 4581 | (read-seq {} stream)) |
4571 | 4582 | ([opts stream] |
4572 | 4583 | (let [read (:read opts basilisp.lang.reader/read)] |
4573 | | - (seq (read stream |
4574 | | - *resolver* |
4575 | | - *data-readers* |
4576 | | - (:eof opts) |
4577 | | - (= (:eof opts) :eofthrow) |
4578 | | - (:features opts) |
4579 | | - (not= :preserve (:read-cond opts)) |
4580 | | - *default-data-reader-fn* |
4581 | | - ** |
4582 | | - :init-line (:init-line opts) |
4583 | | - :init-column (:init-column opts)))))) |
| 4584 | + (iterator-seq (read stream |
| 4585 | + *resolver* |
| 4586 | + *data-readers* |
| 4587 | + (:eof opts) |
| 4588 | + (= (:eof opts) :eofthrow) |
| 4589 | + (:features opts) |
| 4590 | + (not= :preserve (:read-cond opts)) |
| 4591 | + *default-data-reader-fn* |
| 4592 | + ** |
| 4593 | + :init-line (:init-line opts) |
| 4594 | + :init-column (:init-column opts)))))) |
4584 | 4595 |
|
4585 | 4596 | (defn read-string |
4586 | 4597 | "Read a string of Basilisp code. |
|
5497 | 5508 | string. Otherwise, return a vector with the string in the first position and the |
5498 | 5509 | match groups in the following positions." |
5499 | 5510 | [pattern s] |
5500 | | - (lazy-re-seq (seq (re/finditer pattern s)))) |
| 5511 | + (lazy-re-seq (iterator-seq (re/finditer pattern s)))) |
5501 | 5512 |
|
5502 | 5513 | ;;;;;;;;;;;;;;;;; |
5503 | 5514 | ;; Hierarchies ;; |
|
6125 | 6136 | fmeta (merge (meta fn-decl) (meta name)) |
6126 | 6137 | decorators (:decorators fmeta)] |
6127 | 6138 | (if decorators |
6128 | | - (loop [wrappers (seq (python/reversed decorators)) |
| 6139 | + (loop [wrappers (iterator-seq (python/reversed decorators)) |
6129 | 6140 | final fn-decl] |
6130 | 6141 | (if (seq wrappers) |
6131 | 6142 | (recur (rest wrappers) |
|
7640 | 7651 | (mapcat (fn [^os/DirEntry entry] |
7641 | 7652 | (if (.is-dir entry) |
7642 | 7653 | ;; immediate subdirectory |
7643 | | - (os/scandir (.-path entry)) |
| 7654 | + (iterator-seq (os/scandir (.-path entry))) |
7644 | 7655 | ;; top level file |
7645 | 7656 | [entry]))) |
7646 | 7657 | (filter #(.is-file %)) |
7647 | 7658 | (map #(pathlib/Path (.-path %))) |
7648 | 7659 | (filter (comp #{"data_readers.lpy" "data_readers.cljc"} name))) |
7649 | | - (eduction (os/scandir dir)))))) |
| 7660 | + (eduction (iterator-seq (os/scandir dir))))))) |
7650 | 7661 | (group-by #(.-parent %)) |
7651 | 7662 | vals |
7652 | 7663 | ;; Only load one data readers file per directory and prefer |
|
0 commit comments