Created
September 8, 2011 18:56
-
-
Save fronx/1204303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Write a function which returns the last element in a sequence. | |
| ;: Special restrictions: last | |
| (= (__ [1 2 3 4 5]) 5) | |
| (= (__ '(5 4 3)) 3) | |
| (= (__ ["b" "c" "d"]) "d") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (find-doc "last") | |
| ;; => | |
| ; ------------------------- | |
| ; ... | |
| ; clojure.core/last | |
| ; ([coll]) | |
| ; Return the last item in coll, in linear time | |
| ; ------------------------- | |
| ; ... | |
| ; ------------------------- | |
| ; clojure.core/peek | |
| ; ([coll]) | |
| ; For a list or queue, same as first, for a vector, same as, but much | |
| ; more efficient than, last. If the collection is empty, returns nil. | |
| ; ------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (find-doc #"(?i)create.*vector") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (source last) | |
| ;; => | |
| (def | |
| ^{:arglists '([coll]) | |
| :doc "Return the last item in coll, in linear time" | |
| :added "1.0"} | |
| last (fn last [s] | |
| (if (next s) | |
| (recur (next s)) | |
| (first s)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #(peek (vec %)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment