Created
March 16, 2017 04:59
-
-
Save aphyr/66221a2233f2a8934c4f104d8ff193a1 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 distinct-identical | |
| "Like distinct, but only skips elements which are identical to those already | |
| seen." | |
| ([xs] (distinct-identical xs {})) | |
| ([xs seen] | |
| (when (seq xs) | |
| (lazy-seq | |
| (let [x (first xs) | |
| h (hash x) | |
| seen-xs (get seen h)] | |
| (if (not-any? (partial identical? x) (get seen h)) | |
| (cons x (distinct-identical (next xs) | |
| (assoc seen h (conj seen-xs x)))) | |
| (distinct-identical (next xs) seen))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment