Fork me on GitHub
#specter
<
2016-11-17
>
wei00:11:49

is there a way to get the next/previous element of an collection in a transformation? [1 2 3] => [[1 0] [2 1] [3 2]]

wei00:11:58

use case + hacky solution:

((fn [xs]
   (concat [(first xs)]
           (->> (partition 2 1 xs)
                (map (fn [[prev cur]] (assoc cur :prev prev))))))
 [{:id 1} {:id 2} {:id 3} {:id 4}])
=> ({:id 1} {:id 2, :prev {:id 1}} {:id 3, :prev {:id 2}} {:id 4, :prev {:id 3}})