Created
January 1, 2017 23:34
-
-
Save RSNara/a88c995a9035277f9f163f2ad87c639a to your computer and use it in GitHub Desktop.
Silly adjacent implementation.
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 adjacent [n coll] | |
(lazy-seq | |
(if-not (empty? coll) | |
(loop [i 0 | |
element [] | |
others coll] | |
(cond | |
(= i n) (cons element (adjacent n (rest coll))) | |
(empty? others) (list element) | |
:else (recur (inc i) (conj element (first others)) (rest others))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment