Last active
August 29, 2015 14:17
-
-
Save fuadsaud/84526822827b945e147e to your computer and use it in GitHub Desktop.
fuad.im/FUNctional Programming
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 make-composed-comparison [& comparisons] | |
(fn [p1 p2] | |
(let [results (for [comparison comparisons] (comparison p1 p2)) | |
first-non-zero-result | |
(some (fn [result] (if (not (= 0 result)) result nil)) results)] | |
(if (nil? first-non-zero-result) | |
0 | |
first-non-zero-result)))) |
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 make-composed-comparison [& comparisons] | |
(fn [p1 p2] | |
(let [results ((apply juxt comparisons) p1 p2) | |
first-non-zero-result | |
(some (fn [result] (if (not (= 0 result)) result nil)) results)] | |
(if (nil? first-non-zero-result) | |
0 | |
first-non-zero-result)))) |
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 make-composed-comparison [& comparisons] | |
(fn [p1 p2] | |
(let [comparison-results ((apply juxt comparisons) p1 p2)] | |
(or | |
(some #(when (nonzero? %) %) comparison-results) | |
0)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment