Skip to content

Instantly share code, notes, and snippets.

@danielytics
Last active February 16, 2016 17:52
Show Gist options
  • Save danielytics/2fec5a132aeb951fbb79 to your computer and use it in GitHub Desktop.
Save danielytics/2fec5a132aeb951fbb79 to your computer and use it in GitHub Desktop.
(defn infect [{inputs :pathogen/infected
immune :pathogen/immune
traits :pathogen/diseases
:as c}]
;'([protocol [output-key output-fn]] [protocol [output-key output-fn]])
(->>
(for [infected (->> (or (seq inputs) (keys c))
(filter (complement (or immune #{})))
(map (partial get c)))
[protocol [output-key output-fn]] traits]
((juxt (partial satisfies? protocol)
(if-> output-key keyword? constantly identity)
output-fn) infected))
(filter first)
(map (comp vec rest))
(into {})
(merge c)))
(defn disinfect [{inputs :pathogen/infected
incurable :pathogen/incurable
traits :pathogen/diseases
:as c}]
(->>
(for [infected (->> (or (seq inputs) (keys c))
(filter (complement (or incurable #{})))
(map (partial get c)))
[protocol [output-key _]] traits]
((juxt (partial satisfies? protocol)
(if-> output-key keyword? constantly identity)) infected))
(filter first)
(map second)
(apply dissoc c)))
(defn if-> [input conditional true-branch false-branch]
(if (conditional input)
(true-branch input)
(false-branch input)))
(defn wrap [{inputs :wirewrap/inputs
protocol :wirewrap/protocol
[output-key output-fn] :wirewrap/output
:as c}]
(->>
(or (seq inputs) (keys c))
(map (partial get c))
(filter (partial satisfies? protocol))
(map (juxt (if-> output-key keyword? constantly partial)
output-fn))
(into {})
(merge c)))
(defn unwrap [{inputs :wirewrap/inputs
protocol :wirewrap/protocol
[output-key _] :wirewrap/output
:as c}]
(->>
(or (seq inputs) (keys c))
(map (partial get c))
(filter (partial satisfies? protocol))
(map (if-> output-key keyword? constantly partial))
(apply dissoc c)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment