Commits

kumarshantanu  committed 86f968b

add untyped fn, fix "not-" associated fn calls with var args

  • Participants
  • Parent commits 136ad08

Comments (0)

Files changed (2)

File src/main/clj/org/bituf/clj_miscutil.clj

 
 ;; ===== "not" stripped functions =====
 
-(defn any?                  [x] (not (not-any?          x)))
+(defn any?                  [& x] (not (apply not-any?          x)))
 
 
 ;; ===== "not" prefixed functions =====
 
-(defn not-associative?      [x] (not (associative?      x)))
-(defn not-bound?            [x] (not (bound?            x)))
-(defn not-char?             [x] (not (char?             x)))
-(defn not-chunked-seq?      [x] (not (chunked-seq?      x)))
-(defn not-class?            [x] (not (class?            x)))
-(defn not-coll?             [x] (not (coll?             x)))
-(defn not-contains?         [x] (not (contains?         x)))
-(defn not-counted?          [x] (not (counted?          x)))
-(defn not-decimal?          [x] (not (decimal?          x)))
-(defn not-delay?            [x] (not (delay?            x)))
-(defn not-distinct?         [x] (not (distinct?         x)))
-(defn not-empty?            [x] (not (empty?            x)))
-(defn not-even?             [x] (not (even?             x)))
-(defn not-extends?          [x] (not (extends?          x)))
-(defn not-false?            [x] (not (false?            x)))
-(defn not-float?            [x] (not (float?            x)))
-(defn not-fn?               [x] (not (fn?               x)))
-(defn not-future-cancelled? [x] (not (future-cancelled? x)))
-(defn not-future-done?      [x] (not (future-done?      x)))
-(defn not-future?           [x] (not (future?           x)))
-(defn not-identical?        [x] (not (identical?        x)))
-(defn not-ifn?              [x] (not (ifn?              x)))
-(defn not-instance?         [x] (not (instance?         x)))
-(defn not-integer?          [x] (not (integer?          x)))
-(defn not-isa?              [x] (not (isa?              x)))
-(defn not-keyword?          [x] (not (keyword?          x)))
-(defn not-list?             [x] (not (list?             x)))
-(defn not-map?              [x] (not (map?              x)))
-(defn not-neg?              [x] (not (neg?              x)))
-(defn not-nil?              [x] (not (nil?              x)))
-(defn not-number?           [x] (not (number?           x)))
-(defn not-odd?              [x] (not (odd?              x)))
-(defn not-pos?              [x] (not (pos?              x)))
-(defn not-ratio?            [x] (not (ratio?            x)))
-(defn not-rational?         [x] (not (rational?         x)))
-(defn not-reversible?       [x] (not (reversible?       x)))
-(defn not-satisfies?        [x] (not (satisfies?        x)))
-(defn not-seq?              [x] (not (seq?              x)))
-(defn not-sequential?       [x] (not (sequential?       x)))
-(defn not-set?              [x] (not (set?              x)))
-(defn not-sorted?           [x] (not (sorted?           x)))
-(defn not-special-symbol?   [x] (not (special-symbol?   x)))
-(defn not-string?           [x] (not (string?           x)))
-(defn not-symbol?           [x] (not (symbol?           x)))
-(defn not-thread-bound?     [x] (not (thread-bound?     x)))
-(defn not-true?             [x] (not (true?             x)))
-(defn not-var?              [x] (not (var?              x)))
-(defn not-vector?           [x] (not (vector?           x)))
-(defn not-zero?             [x] (not (zero?             x)))
+(defn not-associative?      [& x] (not (apply associative?      x)))
+(defn not-bound?            [& x] (not (apply bound?            x)))
+(defn not-char?             [& x] (not (apply char?             x)))
+(defn not-chunked-seq?      [& x] (not (apply chunked-seq?      x)))
+(defn not-class?            [& x] (not (apply class?            x)))
+(defn not-coll?             [& x] (not (apply coll?             x)))
+(defn not-contains?         [& x] (not (apply contains?         x)))
+(defn not-counted?          [& x] (not (apply counted?          x)))
+(defn not-decimal?          [& x] (not (apply decimal?          x)))
+(defn not-delay?            [& x] (not (apply delay?            x)))
+(defn not-distinct?         [& x] (not (apply distinct?         x)))
+(defn not-empty?            [& x] (not (apply empty?            x)))
+(defn not-even?             [& x] (not (apply even?             x)))
+(defn not-extends?          [& x] (not (apply extends?          x)))
+(defn not-false?            [& x] (not (apply false?            x)))
+(defn not-float?            [& x] (not (apply float?            x)))
+(defn not-fn?               [& x] (not (apply fn?               x)))
+(defn not-future-cancelled? [& x] (not (apply future-cancelled? x)))
+(defn not-future-done?      [& x] (not (apply future-done?      x)))
+(defn not-future?           [& x] (not (apply future?           x)))
+(defn not-identical?        [& x] (not (apply identical?        x)))
+(defn not-ifn?              [& x] (not (apply ifn?              x)))
+(defn not-instance?         [& x] (not (apply instance?         x)))
+(defn not-integer?          [& x] (not (apply integer?          x)))
+(defn not-isa?              [& x] (not (apply isa?              x)))
+(defn not-keyword?          [& x] (not (apply keyword?          x)))
+(defn not-list?             [& x] (not (apply list?             x)))
+(defn not-map?              [& x] (not (apply map?              x)))
+(defn not-neg?              [& x] (not (apply neg?              x)))
+(defn not-nil?              [& x] (not (apply nil?              x)))
+(defn not-number?           [& x] (not (apply number?           x)))
+(defn not-odd?              [& x] (not (apply odd?              x)))
+(defn not-pos?              [& x] (not (apply pos?              x)))
+(defn not-ratio?            [& x] (not (apply ratio?            x)))
+(defn not-rational?         [& x] (not (apply rational?         x)))
+(defn not-reversible?       [& x] (not (apply reversible?       x)))
+(defn not-satisfies?        [& x] (not (apply satisfies?        x)))
+(defn not-seq?              [& x] (not (apply seq?              x)))
+(defn not-sequential?       [& x] (not (apply sequential?       x)))
+(defn not-set?              [& x] (not (apply set?              x)))
+(defn not-sorted?           [& x] (not (apply sorted?           x)))
+(defn not-special-symbol?   [& x] (not (apply special-symbol?   x)))
+(defn not-string?           [& x] (not (apply string?           x)))
+(defn not-symbol?           [& x] (not (apply symbol?           x)))
+(defn not-thread-bound?     [& x] (not (apply thread-bound?     x)))
+(defn not-true?             [& x] (not (apply true?             x)))
+(defn not-var?              [& x] (not (apply var?              x)))
+(defn not-vector?           [& x] (not (apply vector?           x)))
+(defn not-zero?             [& x] (not (apply zero?             x)))
 
 
 ;; ===== Maps Transformation =====
     (apply typed t-obj types)))
 
 
+(defn untyped
+  "Return object with all type annotation removed."
+  [obj] {:post [(verify-arg (obj? %))]
+         :pre  [(verify-arg (obj? obj))]}
+  (let [m (meta obj)]
+    (with-meta obj (dissoc m :type))))
+
+
 ;; ===== Keyword to/from string conversion =====
 
 

File src/test/clj/org/bituf/test_clj_miscutil.clj

       (is (typed? t :abc))
       (is (typed? t :def))
       (is (typed? t :ghi))))
+  (testing "untyped"
+    (is (not-contains? (untyped (typed {} :abc :def)) :type)))
+  (testing "type-meta"
+    (is (= (type-meta (typed {} :abc)) :abc)))
   (testing "hierarchy-test for typed?"
     (let [e (make-hierarchy)
           g (derive e ::employee ::salaried)