Skip to content

Instantly share code, notes, and snippets.

@omasanori
Created January 6, 2012 02:41
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 omasanori/1568687 to your computer and use it in GitHub Desktop.
Save omasanori/1568687 to your computer and use it in GitHub Desktop.
;;; See also
;; http://d.hatena.ne.jp/mkut/20111226/1324907006
;; http://blog.livedoor.jp/dankogai/archives/51763038.html
;; My straightforward but naive solution.
(defn naive-map-between
[f coll]
(lazy-seq
(let [[x y] coll]
(when (and x y)
(cons (f x y) (naive-map-between f (rest coll)))))))
;; based on kohyama's simple and elegant solution available from
;; http://twitter.com/kohyama/status/155115625155538944
(defn kohyama-map-between
[f coll]
(map (fn [[x y]] (f x y)) (partition 2 1 coll)))
;; My another solution similar to Haskell solutions using zipWith.
(defn another-map-between
[f coll]
(map f coll (rest coll))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment