diff options
author | Chouser <chouser@n01se.net> | 2009-10-16 10:37:11 -0400 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2009-10-16 10:37:11 -0400 |
commit | 0ba40a260162330836b97f6d1bf3466404a63b55 (patch) | |
tree | 0bb6eca5c0def0e39b0d27221ed72185e1cfb699 | |
parent | 1ca9c8b9322882a0d84db9007047d223d11f2c3f (diff) |
Implement take-last Fixes #151
-rw-r--r-- | src/clj/clojure/core.clj | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 8a00c6d2..90e3f76f 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1802,6 +1802,15 @@ ([s] (drop-last 1 s)) ([n s] (map (fn [x _] x) s (drop n s)))) +(defn take-last + "Returns a seq of the last n items in coll. Depending on the type + of coll may be no better than linear time. For vectors, see also subvec." + [n coll] + (loop [s (seq coll), lead (seq (drop n coll))] + (if lead + (recur (next s) (next lead)) + s))) + (defn drop-while "Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns nil." |