Last active
August 29, 2015 14:06
-
-
Save firesofmay/0abc1294b9fd96386a03 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 fancy-mod | |
| "Takes the following parameters and | |
| returns a function which takes two integer numbers. | |
| - operator-fn => Mathematical Operator : + OR * OR / OR - | |
| - mod-by => number to mod by, example 2. | |
| - output-fn => str or int. | |
| Example: | |
| ((fancy-mod + 2 str) 10 11) | |
| ;;=> \"2\" | |
| Also can be used like | |
| > (def mod-by-3->int (fancy-mod + 3 int)) | |
| > (mod-by-3->int 11 11) | |
| ;;=> 1 | |
| Note: Throws exception if invalid parameters passed!" | |
| [operator-fn mod-by output-fn] | |
| {:pre [(#{+ - / *} operator-fn) | |
| (integer? mod-by) | |
| (#{str int} output-fn)]} | |
| (fn [num1 num2] | |
| {:pre [(integer? num1) | |
| (integer? num2)]} | |
| (output-fn (#(mod % mod-by) | |
| (operator-fn num1 | |
| num2))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment