Created
May 14, 2015 03:10
-
-
Save selfsame/9db890341c0c072c06aa to your computer and use it in GitHub Desktop.
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
| (defmacro sandwich [col args & code] | |
| "[col [prev current next] first-form 1-n-forms last-form]" | |
| (let [top# (first code) | |
| meat# (butlast (rest code)) | |
| bottom# (last code)] | |
| `(remove nil? (apply concat (map-indexed | |
| (fn [i# v#] | |
| (let [~args [(get ~col (dec i#)) v# (get ~col (inc i#))]] | |
| (cond (= i# 0) [~top# ~@meat#] | |
| (= i# (dec (count ~col))) [~@meat# ~bottom#] | |
| :else [~@meat#]))) | |
| ~col))))) | |
| (sandwich ['bread 'tomato 'lettuce 'bacon 'bread] | |
| [before item after] | |
| 'olive | |
| (when-not after 'mayo) | |
| (if (= 'tomato before) | |
| ['soggy item] | |
| item) | |
| (when-not before 'mayo) | |
| 'paper-plate) | |
| ;(olive bread mayo tomato [soggy lettuce] bacon mayo bread paper-plate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment