Back
complement (clj)
(source)function
(complement f)
Takes a fn f and returns a fn that takes the same arguments as f,
has the same effects, if any, and returns the opposite truth value.
Examples
clojure/core.typed
(ns clojure.core.typed.test.pred
(:require
[clojure.test :refer :all]
[clojure.core.typed :as t]))
(deftest hmap-pred-test
(is ((every-pred
(t/pred
(t/HMap)))
{}
{:a 'blah}))
(is ((complement
(t/pred
(t/HMap :mandatory {:a Number})))
{}))
(is ((t/pred
(t/HMap :mandatory {:a Number}))
{:a 1}))
(is ((every-pred
(t/pred
(t/HMap :optional {:a Number})))
{:a 1}
{}
{:b 'a}))
(is ((every-pred
(t/pred
(t/HMap :absent-keys #{:a})))
{:b 'a}))
(is (not
((every-pred
(t/pred
(t/HMap :absent-keys #{:a})))
{:a 'a})))
)
(deftest hvec-pred-test
(is ((t/pred '[Number Number])
[1 2]))
(is ((every-pred
(complement
(t/pred '[Number Number])))
['a 2]
[]
[1]
[1 2 3]))
(is ((every-pred
(t/pred
'[Number Number Number *]))
[1 2]
[1 2 3]
[1 2 3 4 5 6 6 7 4 2 1]))
(is ((every-pred
(complement
(t/pred
'[Number Number Number *])))
[]
[1]
[1 2 'a]
[1 2 3 4 5 'a 6 7 4 2 1])))
(deftest rec-pred-test
(is ((every-pred
(t/pred (t/Rec [x] (t/U '[x] Number))))
1
'[1]
'[[1]]
'[[[[[2.2]]]]]))
(is ((every-pred
(t/pred (t/Rec [x] (t/U '{:a x} Number))))
1
'{:a 1}
'{:a {:a 1}}
'{:a {:a {:a {:a {:a 1}}}}}))
(is ((every-pred
(complement
(t/pred (t/Rec [x] (t/U '[x] Number)))))
'[1 1]
'[[1] [1]])))
(deftest singleton-pred-test
(is ((t/pred true)
true))
(is ((t/pred (t/Value true))
true))
(is ((t/pred false)
false))
(is ((t/pred (t/Value false))
false))
(is ((t/pred 'sym)
'sym))
(is ((t/pred (t/Value sym))
'sym))
(is ((t/pred ':sym)
':sym))
(is ((t/pred (t/Value :sym))
':sym))
(is ((t/pred nil)
nil))
(is ((t/pred (t/Value nil))
nil))
(is ((t/pred '1)
1))
(is ((every-pred
(complement
(t/pred '1)))
1.0))
(is ((t/pred (t/Value 1))
1)))
(deftest countrange-pred-test
(is ((every-pred
(t/pred (t/CountRange 0)))
nil
[]
{}
'()))
(is ((every-pred
(complement
(t/pred (t/CountRange 0))))
; only supports clojure collections
(into-array [])
)))
(deftest intersect-pred-test
(is ((every-pred
(t/pred (t/I Number Long)))
1))
(is ((every-pred
(complement
(t/pred (t/I Number Long))))
1.1))
(is ((every-pred
(complement
(t/pred (t/I Number Long))))
1.1)))
(deftest union-pred-test
(is ((every-pred
(t/pred (t/U Number Long)))
1
1.1))
(is ((every-pred
(complement
(t/pred (t/U Number Long))))
'a))
(is ((every-pred
(complement
(t/pred t/Nothing))
(complement
(t/pred (t/U))))
'a)))
(deftest iseq-pred-test
(is ((every-pred
(t/pred (t/Seq Number)))
'(1 2)))
(is ((every-pred
(complement
(t/pred (t/Seq Number))))
[1 2])))
hraberg/deuce
(ns deuce.emacs.eval
(:use [deuce.emacs-lisp :only (defun defvar)])
(:require [clojure.core :as c]
[deuce.emacs.alloc :as alloc]
[deuce.emacs.data :as data]
[deuce.emacs-lisp.cons :as cons]
[deuce.emacs-lisp :as el])
(:import [clojure.lang Var])
(:refer-clojure :exclude [apply eval macroexpand]))
Do not use `make-local-variable' to make a hook variable buffer-local.
Instead, use `add-hook' and specify t for the LOCAL argument."
(or (some (complement identity) (apply run-hook-with-args hook args))
true))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
;TODO flip filters
cc/complement (t/All [x] [[x :-> t/Any] :-> [x :-> t/Bool]])
; should preserve filters
cc/boolean [t/Any :-> t/Bool]
marick/structural-typing
(ns structural-typing.use.condensed-type-descriptions.f-whole-type-and-implies
(:require [structural-typing.preds :as pred])
(:use midje.sweet
structural-typing.type
structural-typing.global-type
structural-typing.clojure.core
structural-typing.assist.testutil)
(:refer-clojure :except [any?]))
(fact "can also check that the presence of one key implies the nonexistence of another"
(type! :X (pred/implies :a (show-as "missing :b" (complement :b)))
(pred/implies :b (show-as "missing :a" (complement :a))))
marick/structural-typing
(ns structural-typing.assist.f-defaults
(:require [structural-typing.assist.defaults :as subject])
(:use midje.sweet
structural-typing.type
structural-typing.global-type
structural-typing.clojure.core
structural-typing.assist.testutil)
(:refer-clojure :except [any?]))
(fact "special cases for printing"
(type! :X {:x even?
:y (complement even?)})
(fact "a predicate as the incorrect value also prints nicely"
(let [built-fn (complement even?)
msgs (check-for-explanations :X {:y built-fn})]
msgs => (just #"it is the function `")
(.contains (first msgs) (pr-str built-fn)))))