Skip to content

Instantly share code, notes, and snippets.

@kohyama
Last active October 19, 2017 09:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohyama/1708253 to your computer and use it in GitHub Desktop.
Save kohyama/1708253 to your computer and use it in GitHub Desktop.
apply a function to an element and the next element of it in a sequence
(require '[clojure.test :refer (with-test are run-tests)])
(with-test
(defn map-between [f s]
(map (fn [[a b]] (f a b)) (partition 2 1 s)))
(are [f s _ r] (= (map-between f s) r)
#(- %2 %1) '() -> '()
#(- %2 %1) '(0) -> '()
#(- %2 %1) '(0 1) -> '(1)
#(- %2 %1) '(0 1 4) -> '(1 3)
#(- %2 %1) '(0 1 4 9) -> '(1 3 5)))
@kohyama
Copy link
Author

kohyama commented Jul 25, 2013

元ネタはこちら

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment