Last active
August 29, 2015 14:12
-
-
Save augustl/518abd83173444747cd2 to your computer and use it in GitHub Desktop.
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
(defn comp-decision [^Boolean truthyness fns] | |
(fn [initial-ctx] | |
(reduce | |
(fn [ctx decision-fn] | |
(let [decision (decision-fn ctx) | |
result (if (vector? decision) (first decision) decision) | |
context-update (if (vector? decision) (second decision) decision)] | |
(if (= truthyness (boolean result)) | |
(liberator.core/update-context ctx context-update) | |
(reduced decision)))) | |
initial-ctx | |
fns))) | |
(defn comp-pos-decision [& fns] | |
(comp-decision true fns)) | |
(defn comp-neg-decision [& fns] | |
(comp-decision false fns)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment