Public Vars

Back

destructure (clj)

(source)

function

(destructure bindings)

Examples

clojure/core.typed
(ns clojure.core.typed.test.testnew
  (:require [clojure.core.typed :as t] 
            [clojure.test :refer :all]                
            [clojure.core.typed.test.test-utils :refer :all]
            [clojure.core.typed.test.destructure]))

(deftest test-ns-test
  (is-tc-e #(test-ns 'clojure.core.typed.test.destructure) [-> (Map Any Any)]
           :requires [[clojure.test :refer [test-ns]]])
  (is-tc-e #(test-ns *ns*) [-> (Map Any Any)]
           :requires [[clojure.test :refer [test-ns]]]))
typedclojure/typedclojure
(ns ^:no-doc typed.clj.ext.clojure.core__defmethod
  "Typing rules for clojure.core/defmethod"
  (:require [clojure.core.typed.internal :as internal]
            [typed.clj.checker.check :as chk]
            [typed.cljc.analyzer :as ana2]
            [typed.cljc.checker.check.unanalyzed :refer [defuspecial]]))

(defuspecial defuspecial__defmethod
  "defuspecial implementation for clojure.core/defmethod"
  [{:keys [form] :as expr} expected]
  (-> expr
      (update :form internal/add-defmethod-destructure-blame-form)
      ana2/analyze-outer
      (chk/check-expr expected)))
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))))

#?@(:cljs [] :default [
cc/seq-to-map-for-destructuring [t/AnySeqable :-> t/Any]
;cc/seq-to-map-for-destructuring (t/All [x] (t/IFn [(t/HSeq [x]) :-> x]
;                                                  ;; could be anything if seq is of count 1
;                                                  [(t/Seq t/Any) :-> t/Any]))
cc/destructure [t/Any :-> t/Any]
])
typedclojure/typedclojure
(ns ^:no-doc typed-test.clj.ext.clojure.core__let
  (:require [clojure.test :refer [deftest is testing]]
            [clojure.core.typed :as t]
            [typed.clj.checker.parse-unparse :as prs]
            [typed.clj.checker.test-utils :refer :all]))

  (is (t/check-ns 'typed-test.clj.ext.clojure.core.succeed.destructure))
  ;;TODO improve inference
  #_
  (is-tc-e (let [[a b] nil] [a b])
           '[nil nil])
  #_ ;;FIXME
  (is-tc-e (let [;; erase object
                 [a b] (t/ann-form nil nil)
                 a (or a 42)]
             a)
           (t/Val 42)))
typedclojure/typedclojure
(ns typed-test.clj.ext.clojure.core__fn
  (:require [clojure.test :refer [deftest is]]
            [typed.clojure :as t]
            [typed.clj.ext.clojure.core__fn :as sut]))

(deftest prep-tc-meta-test
  (let [[form metas] (sut/prep-tc-meta
                       '(cc/fn [^{:other-meta 2} a] (inc a)))]
    (is (nil? metas))
    (is (= '(cc/fn [a] (inc a)) form))
    (is (= {:other-meta 2, :clojure.core.typed.internal/destructure-blame-form '(cc/fn [a] (inc a))}
           (-> form second first meta))))
  (let [[form metas] (sut/prep-tc-meta
                       '(cc/fn 
                          [^{::t/- t/Int :other-meta 2} a] (inc a)))]
    (is (= '#{{:type :fixed :method-pos 0 :nfixed 1 :has-rest? false :form a :fixed-pos 0 :annotated true}
              {:type :argv :method-pos 0 :nfixed 1 :has-rest? false :form [a]}}
           metas))
    (is (= '(cc/fn [a] (inc a)) form))
    (is (= {:other-meta 2, :clojure.core.typed.internal/destructure-blame-form '(cc/fn [a] (inc a))}
           (-> form second first meta))))
  (let [[form metas] (sut/prep-tc-meta
                       '(cc/fn ^{::t/- t/Bool :yet-more-meta 3}
                          [^{::t/- t/Int :other-meta 2} a] (inc a)))]
    (is (= '#{{:type :fixed :method-pos 0 :nfixed 1 :has-rest? false :form a :fixed-pos 0 :annotated true}
              {:type :argv :method-pos 0 :nfixed 1 :has-rest? false :form [a] :annotated true}}
           metas))
    (is (= '(cc/fn [a] (inc a)) form))
    (is (= {:other-meta 2, :clojure.core.typed.internal/destructure-blame-form '(cc/fn [a] (inc a))}
           (-> form second first meta)))
    (is (= {:yet-more-meta 3}
           (-> form second meta))))
  (let [[form metas] (sut/prep-tc-meta
                       '(cc/fn ^{::t/- [t/Bool :-> t/Int] :even-more-meta 3}
                          _a
                          [a] (inc a)))]
    (is (= '#{{:type :fixed :method-pos 0 :nfixed 1 :has-rest? false :form a :fixed-pos 0}
              {:type :argv :method-pos 0 :nfixed 1 :has-rest? false :form [a]}
              {:type :name :form _a :annotated true}}
           metas))
    (is (= '(cc/fn _a [a] (inc a)) form))
    (is (= {:even-more-meta 3}
           (-> form second meta)))))