Skip to content

Instantly share code, notes, and snippets.

@AdamSaleh
Created June 6, 2013 14:14
Show Gist options
  • Save AdamSaleh/5721832 to your computer and use it in GitHub Desktop.
Save AdamSaleh/5721832 to your computer and use it in GitHub Desktop.
(defn single? [a]
(= 1 (count a)))
(defmacro map-check [map-features & predicates]
(let [symbols #(->> % (into []) flatten
(filter symbol?)
(into #{}))]
`(fn [m#]
(and (map? m#)
(<= 1 (count (l/run 1 [~@(symbols map-features)]
(l/featurec m# ~map-features)
~@(for [predicate predicates]
`(l/project [~@(intersection
(symbols map-features)
(symbols predicate))]
(l/== true (~@predicate)))
))))))))
(def symbols #(->> % (into []) flatten
(filter symbol?)
(into #{})))
(defmacro map-features? [m features]
`(<= 1 (count (l/run 1 [~@(symbols features)]
(l/featurec ~m ~features)))))
(defmacro map-predicate? [m features predicate]
`(<= 1 (count (l/run 1 [~@(symbols features)]
(l/featurec ~m ~features)
(l/project [~@(intersection
(symbols features)
(symbols predicate))]
(l/== true (~@predicate)))
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment