Created
February 16, 2017 19:20
-
-
Save frenchy64/5673c2ce78e5a7c051f508819f0e6dda to your computer and use it in GitHub Desktop.
Automatic annotations for `for`
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- multi-perm | |
"Handles the case when you want the permutations of a list with duplicate items." | |
[l] | |
(let [f (frequencies l), | |
v (vec (distinct l)), | |
indices (apply concat | |
(for ^{::t/ann (t/Coll Long)} [^{::t/ann Long} i (range (count v))] | |
(repeat (f (v i)) i)))] | |
(map (partial map v) (lex-permutations indices)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment