Last active
October 19, 2017 09:05
-
-
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
This file contains 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
(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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
元ネタはこちら