|
418 | 418 |
|
419 | 419 | (defn concat |
420 | 420 | "Returns a lazy sequence representing the concatenation of the elements in the supplied colls." |
421 | | - ([] nil) |
422 | | - ([x] (seq x)) |
| 421 | + ([] (lazy-seq nil)) |
| 422 | + ([x] (lazy-seq x)) |
423 | 423 | ([x y] |
424 | 424 | (lazy-seq |
425 | 425 | (if (seq x) |
426 | 426 | (cons (first x) (concat (more x) y)) |
427 | | - (seq y)))) |
| 427 | + y))) |
428 | 428 | ([x y & zs] |
429 | 429 | (let [cat (fn cat [xys zs] |
430 | 430 | (lazy-seq |
431 | 431 | (if (seq xys) |
432 | 432 | (cons (first xys) (cat (more xys) zs)) |
433 | 433 | (when zs |
434 | | - (seq (cat (first zs) (rest zs)))))))] |
| 434 | + (cat (first zs) (rest zs))))))] |
435 | 435 | (cat (concat x y) zs)))) |
436 | 436 |
|
437 | 437 | ;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;; |
|
1507 | 1507 | (lazy-seq (step pred coll)))) |
1508 | 1508 |
|
1509 | 1509 | (defn cycle |
1510 | | - "Returns a lazy (infinite!) seq of repetitions of the items in |
1511 | | - coll." |
1512 | | - [coll] |
1513 | | - (when (seq coll) |
1514 | | - (let [rep (fn thisfn [xs] |
1515 | | - (if xs |
1516 | | - (lazy-cons (first xs) (thisfn (rest xs))) |
1517 | | - (recur (seq coll))))] |
1518 | | - (rep (seq coll))))) |
| 1510 | + "Returns a lazy (infinite!) sequence of repetitions of the items in coll." |
| 1511 | + [coll] (lazy-seq (concat coll (cycle coll)))) |
1519 | 1512 |
|
1520 | 1513 | (defn split-at |
1521 | 1514 | "Returns a vector of [(take n coll) (drop n coll)]" |
|
1528 | 1521 | [(take-while pred coll) (drop-while pred coll)]) |
1529 | 1522 |
|
1530 | 1523 | (defn repeat |
1531 | | - "Returns a lazy (infinite!) seq of xs." |
1532 | | - [x] (lazy-cons x (repeat x))) |
| 1524 | + "Returns a lazy (infinite!, or length n if supplied) sequence of xs." |
| 1525 | + ([x] (lazy-seq (cons x (repeat x)))) |
| 1526 | + ([n x] (take n (repeat x)))) |
1533 | 1527 |
|
1534 | 1528 | (defn replicate |
1535 | 1529 | "Returns a lazy seq of n xs." |
1536 | 1530 | [n x] (take n (repeat x))) |
1537 | 1531 |
|
1538 | 1532 | (defn iterate |
1539 | | - "Returns a lazy seq of x, (f x), (f (f x)) etc. f must be free of side-effects" |
1540 | | - [f x] (lazy-cons x (iterate f (f x)))) |
| 1533 | + "Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects" |
| 1534 | + [f x] (cons x (lazy-seq (iterate f (f x))))) |
1541 | 1535 |
|
1542 | 1536 | (defn range |
1543 | 1537 | "Returns a lazy seq of nums from start (inclusive) to end |
|
1596 | 1590 | rdr must implement java.io.BufferedReader." |
1597 | 1591 | [#^java.io.BufferedReader rdr] |
1598 | 1592 | (let [line (. rdr (readLine))] |
1599 | | - (when line |
1600 | | - (lazy-cons line (line-seq rdr))))) |
| 1593 | + (lazy-seq |
| 1594 | + (when line |
| 1595 | + (cons line (line-seq rdr)))))) |
1601 | 1596 |
|
1602 | 1597 | (defn comparator |
1603 | 1598 | "Returns an implementation of java.util.Comparator based upon pred." |
|
1634 | 1629 | ([n coll] |
1635 | 1630 | (partition n n coll)) |
1636 | 1631 | ([n step coll] |
1637 | | - (when (seq coll) |
1638 | | - (let [p (take n coll)] |
1639 | | - (when (= n (count p)) |
1640 | | - (lazy-cons p (partition n step (drop step coll)))))))) |
| 1632 | + (lazy-seq |
| 1633 | + (when (seq coll) |
| 1634 | + (let [p (take n coll)] |
| 1635 | + (when (= n (count p)) |
| 1636 | + (cons p (partition n step (drop step coll))))))))) |
1641 | 1637 |
|
1642 | 1638 | ;; evaluation |
1643 | 1639 |
|
|
2237 | 2233 | row-struct (apply create-struct keys) |
2238 | 2234 | row-values (fn [] (map (fn [#^Integer i] (. rs (getObject i))) idxs)) |
2239 | 2235 | rows (fn thisfn [] |
2240 | | - (when (. rs (next)) |
2241 | | - (lazy-cons (apply struct row-struct (row-values)) (thisfn))))] |
| 2236 | + (lazy-seq |
| 2237 | + (when (. rs (next)) |
| 2238 | + (cons (apply struct row-struct (row-values)) (thisfn)))))] |
2242 | 2239 | (rows))) |
2243 | 2240 |
|
2244 | 2241 | (defn set |
|
2381 | 2378 | (defn take-nth |
2382 | 2379 | "Returns a lazy seq of every nth item in coll." |
2383 | 2380 | [n coll] |
2384 | | - (when (seq coll) |
2385 | | - (lazy-cons (first coll) (take-nth n (drop n coll))))) |
| 2381 | + (lazy-seq |
| 2382 | + (when (seq coll) |
| 2383 | + (cons (first coll) (take-nth n (drop n coll)))))) |
2386 | 2384 |
|
2387 | 2385 | (defn interleave |
2388 | 2386 | "Returns a lazy seq of the first item in each coll, then the second |
|
0 commit comments