Skip to content

Instantly share code, notes, and snippets.

@zahardzhan
Created February 20, 2010 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zahardzhan/309625 to your computer and use it in GitHub Desktop.
Save zahardzhan/309625 to your computer and use it in GitHub Desktop.
fn namespace
(ns fn (:refer-clojure :exclude [not and or]))
(def not complement)
(defn and "Functions intersection."
([f] f)
([f & fs] (let [chain (apply and fs)]
(fn [& xs] (clojure.core/and (apply f xs)
(apply chain xs))))))
(defn or "Functions union."
([f] f)
([f & fs] (let [chain (apply or fs)]
(fn [& xs] (clojure.core/or (apply f xs)
(apply chain xs))))))
(defun fint (fn &rest fns)
(if (null fns)
fn
(let ((chain (apply #'fint fns)))
#'(lambda (x)
(and (funcall fn x) (funcall chain x))))))
(defun fun (fn &rest fns)
(if (null fns)
fn
(let ((chain (apply #'fun fns)))
#'(lambda (x)
(or (funcall fn x) (funcall chain x))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment