Created
February 20, 2010 10:45
-
-
Save zahardzhan/309625 to your computer and use it in GitHub Desktop.
fn namespace
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
(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)))))) |
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
(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