Skip to content

Instantly share code, notes, and snippets.

@frenchy64
Created February 16, 2017 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frenchy64/5673c2ce78e5a7c051f508819f0e6dda to your computer and use it in GitHub Desktop.
Save frenchy64/5673c2ce78e5a7c051f508819f0e6dda to your computer and use it in GitHub Desktop.
Automatic annotations for `for`
(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