Created
December 18, 2009 02:24
-
-
Save francoisdevlin/259237 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
| (defn- same-dispatch [& args] | |
| (class (last args))) | |
| (defmulti | |
| #^{:doc | |
| "same is a mutlimethod that is designed to \"undo\" seq. | |
| It expects a seq-fn that returns a normal seq, and the | |
| appropraite args. It converts the resulting seq into the same | |
| type as the last argument. If it is a sorted seq, the | |
| comparator is preserved. | |
| This operation is fundamentally eager, unless a | |
| clojure.lang.LazySeq is presented. In this case laziness is | |
| preserved, as it is not possible to infer the original data | |
| type." | |
| :arglists '([seq-fn & args])} | |
| same same-dispatch) | |
| (defmethod same String | |
| [hof & args] | |
| (apply str (apply hof f args))) | |
| (defmethod same clojure.lang.LazySeq | |
| [hof & args] | |
| (apply hof args)) | |
| (defmethod same :default | |
| [hof & args] | |
| (into (empty (last args)) (apply hof args))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment