-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Clojure functions that contain metadata with custom FnWithMeta #150
Changes from all commits
0d04686
3fc564e
6968c26
0d75db1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,91 @@ | ||
(ns methodical.impl.combo.common | ||
"Utility functions for implementing method combinations.") | ||
"Utility functions for implementing method combinations." | ||
(:require [methodical.util :as u])) | ||
|
||
(defn partial* | ||
"[[clojure.core/partial]] but with more direct arities." | ||
([inner] inner) | ||
([inner a] | ||
(fn | ||
([] (inner a)) | ||
([p] (inner a p)) | ||
([p q] (inner a p q)) | ||
([p q r] (inner a p q r)) | ||
([p q r s] (inner a p q r s)) | ||
([p q r s t] (inner a p q r s t)) | ||
([p q r s t u] (inner a p q r s t u)) | ||
([p q r s t u v] (inner a p q r s t u v)) | ||
([p q r s t u v x] (inner a p q r s t u v x)) | ||
([p q r s t u v x y] (inner a p q r s t u v x y)) | ||
([p q r s t u v x y & z] (apply inner a p q r s t u v x y z)))) | ||
([inner a b] | ||
(fn | ||
([] (inner a b)) | ||
([p] (inner a b p)) | ||
([p q] (inner a b p q)) | ||
([p q r] (inner a b p q r)) | ||
([p q r s] (inner a b p q r s)) | ||
([p q r s t] (inner a b p q r s t)) | ||
([p q r s t u] (inner a b p q r s t u)) | ||
([p q r s t u v] (inner a b p q r s t u v)) | ||
([p q r s t u v x] (inner a b p q r s t u v x)) | ||
([p q r s t u v x y] (inner a b p q r s t u v x y)) | ||
([p q r s t u v x y & z] (apply inner a b p q r s t u v x y z)))) | ||
([inner a b c] | ||
(fn | ||
([] (inner a b c)) | ||
([p] (inner a b c p)) | ||
([p q] (inner a b c p q)) | ||
([p q r] (inner a b c p q r)) | ||
([p q r s] (inner a b c p q r s)) | ||
([p q r s t] (inner a b c p q r s t)) | ||
([p q r s t u] (inner a b c p q r s t u)) | ||
([p q r s t u v] (inner a b c p q r s t u v)) | ||
([p q r s t u v x] (inner a b c p q r s t u v x)) | ||
([p q r s t u v x y] (inner a b c p q r s t u v x y)) | ||
([p q r s t u v x y & z] (apply inner a b c p q r s t u v x y z)))) | ||
([inner a b c d] | ||
(fn | ||
([] (inner a b c d)) | ||
([p] (inner a b c d p)) | ||
([p q] (inner a b c d p q)) | ||
([p q r] (inner a b c d p q r)) | ||
([p q r s] (inner a b c d p q r s)) | ||
([p q r s t] (inner a b c d p q r s t)) | ||
([p q r s t u] (inner a b c d p q r s t u)) | ||
([p q r s t u v] (inner a b c d p q r s t u v)) | ||
([p q r s t u v x] (inner a b c d p q r s t u v x)) | ||
([p q r s t u v x y] (inner a b c d p q r s t u v x y)) | ||
([p q r s t u v x y & z] (apply inner a b c d p q r s t u v x y z)))) | ||
([inner a b c d e] | ||
(fn | ||
([] (inner a b c d e)) | ||
([p] (inner a b c d e p)) | ||
([p q] (inner a b c d e p q)) | ||
([p q r] (inner a b c d e p q r)) | ||
([p q r s] (inner a b c d e p q r s)) | ||
([p q r s t] (inner a b c d e p q r s t)) | ||
([p q r s t u] (inner a b c d e p q r s t u)) | ||
([p q r s t u v] (inner a b c d e p q r s t u v)) | ||
([p q r s t u v x] (inner a b c d e p q r s t u v x)) | ||
([p q r s t u v x y] (inner a b c d e p q r s t u v x y)) | ||
([p q r s t u v x y & z] (apply inner a e b c d p q r s t u v x y z)))) | ||
([inner a b c d e f] | ||
(fn | ||
([] (inner a b c d e f)) | ||
([p] (inner a b c d e f p)) | ||
([p q] (inner a b c d e f p q)) | ||
([p q r] (inner a b c d e f p q r)) | ||
([p q r s] (inner a b c d e f p q r s)) | ||
([p q r s t] (inner a b c d e f p q r s t)) | ||
([p q r s t u] (inner a b c d e f p q r s t u)) | ||
([p q r s t u v] (inner a b c d e f p q r s t u v)) | ||
([p q r s t u v x] (inner a b c d e f p q r s t u v x)) | ||
([p q r s t u v x y] (inner a b c d e f p q r s t u v x y)) | ||
([p q r s t u v x y & z] (apply inner a e f b c d p q r s t u v x y z)))) | ||
([inner a b c d e f & more] | ||
(fn [& args] | ||
(inner a b c d e f (concat more args))))) | ||
|
||
(defn combine-primary-methods | ||
"Combine all `primary-methods` into a single combined method. Each method is partially bound with a `next-method` | ||
|
@@ -8,7 +94,8 @@ | |
(when (seq primary-methods) | ||
(reduce | ||
(fn [next-method primary-method] | ||
(with-meta (partial primary-method next-method) (meta primary-method))) | ||
(u/fn-with-meta (partial* (u/unwrap-fn-with-meta primary-method) next-method) | ||
Comment on lines
-11
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if maybe we should also have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! |
||
(meta primary-method))) | ||
nil | ||
(reverse primary-methods)))) | ||
|
||
|
@@ -19,7 +106,8 @@ | |
[combined-method around-methods] | ||
(reduce | ||
(fn [combined-method around-method] | ||
(with-meta (partial around-method combined-method) (meta around-method))) | ||
(u/fn-with-meta (partial* (u/unwrap-fn-with-meta around-method) combined-method) | ||
(meta around-method))) | ||
combined-method | ||
around-methods)) | ||
|
||
|
@@ -36,7 +124,7 @@ | |
(apply f fn-tail) | ||
|
||
(vector? (ffirst fn-tail)) | ||
(map (partial transform-fn-tail f) fn-tail) | ||
(map (partial* transform-fn-tail f) fn-tail) | ||
|
||
:else | ||
(throw (ex-info (format "Invalid fn tail: %s. Expected ([arg*] & body) or (([arg*] & body)+)" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add a Kondo
:discouraged-var
rule forclojure.core/partial
but I can do that separately