Back
simple-symbol? (clj)
(source)function
(simple-symbol? x)
Return true if x is a symbol without a namespace
Examples
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))))
cc/integer? (t/Pred t/AnyInteger)
cc/int? (t/Pred #?(:clj (t/U Long
Integer
Short
Byte)
:cljs (t/U t/CLJSInteger
goog.math.Integer
goog.math.Long)))
cc/pos-int? [t/Any :-> t/Bool
:filters {:then (is #?(:clj (t/U Long
Integer
Short
Byte)
:cljs (t/U t/CLJSInteger
goog.math.Integer
goog.math.Long)) 0)}]
cc/neg-int? [t/Any :-> t/Bool
:filters {:then (is #?(:clj (t/U Long
Integer
Short
Byte)
:cljs (t/U t/CLJSInteger
goog.math.Integer
goog.math.Long)) 0)}]
cc/nat-int? [t/Any :-> t/Bool
:filters {:then (is #?(:clj (t/U Long
Integer
Short
Byte)
:cljs (t/U t/CLJSInteger
goog.math.Integer
goog.math.Long)) 0)}]
cc/number? (t/Pred t/Num)
cc/double? (t/Pred #?(:clj Double
:cljs t/Num))
cc/float? (t/Pred #?(:clj (t/U Double Float)
:cljs t/Num))
cc/ident? (t/Pred t/Ident)
cc/simple-ident? [t/Any :-> t/Bool :filters {:then (is t/Ident 0)}]
cc/qualified-ident? [t/Any :-> t/Bool :filters {:then (is t/Ident 0)}]
cc/simple-symbol? [t/Any :-> t/Bool :filters {:then (is t/Sym 0)}]
cc/qualified-symbol? [t/Any :-> t/Bool :filters {:then (is t/Sym 0)}]
cc/simple-keyword? [t/Any :-> t/Bool :filters {:then (is t/Kw 0)}]
cc/qualified-keyword? [t/Any :-> t/Bool :filters {:then (is t/Kw 0)}]
cc/var? (t/Pred t/AnyVar)
typedclojure/typedclojure
(ns typed-test.malli.schema-to-type
(:require [clojure.test :refer [deftest is]]
[malli.error :as me]
[typed.clojure :as t]
[typed.malli :as tm]
[typed.malli.parse-type :as t->s]
[typed.malli.schema-to-type :as sut]
[typed.clj.checker.parse-unparse :as prs]
[typed.clj.checker.subtype :as sub]
[clojure.core.typed.type-contract :as tcon]
[typed.clj.checker.test-utils :refer [clj is-clj subtype? both-subtype? tc-e tc-err is-tc-e is-tc-err]]
[malli.core :as m]))
(is (= `'[t/AnyInteger]
(sut/malli-syntax->validator-type
[:catn [:int :int]])))
(is (= `[t/AnyInteger :-> t/AnyInteger]
(sut/malli-syntax->validator-type
[:=> [:cat :int] :int])))
(is (= `[t/AnyInteger t/AnyInteger :-> t/AnyInteger]
(sut/malli-syntax->validator-type
[:=> [:cat :int :int] :int])))
(is (= `(t/IFn [t/AnyInteger :-> t/AnyInteger]
[t/AnyInteger t/AnyInteger :-> t/AnyInteger])
(sut/malli-syntax->validator-type
[:=> [:cat :int [:? :int]] :int])))
(is (= `[t/AnyInteger t/AnyInteger :* :-> t/AnyInteger]
(sut/malli-syntax->validator-type
[:=> [:cat :int [:* :int]] :int])))
(is (= `[t/AnyInteger :-> t/AnyInteger]
(sut/malli-syntax->validator-type
[:=> [:catn [:foo :int]] :int])))
(is (= `t/AnyInteger
(sut/malli-syntax->validator-type
'integer?)))
(is (= `(t/Val nil)
(sut/malli-syntax->validator-type 'nil?)
(sut/malli-syntax->validator-type :nil)))
(is (= `(t/HMap)
(sut/malli-syntax->validator-type [:map])))
(is (= `'{:a t/AnyInteger}
(sut/malli-syntax->validator-type [:map [:a :int]])))
(is (= `(t/HMap :optional {:a t/AnyInteger})
(sut/malli-syntax->validator-type [:map [:a {:optional true} :int]])))
(is (= `(t/HMap :mandatory {:b t/Bool}
:optional {:a t/AnyInteger})
(sut/malli-syntax->validator-type [:map [:a {:optional true} :int]
[:b :boolean]])))
(is (thrown? clojure.lang.ExceptionInfo (m/schema [:and])))
(is (thrown? clojure.lang.ExceptionInfo (m/schema [:or])))
(is (= `t/AnyInteger
(sut/malli-syntax->validator-type
[:and
{:title "Age"
:description "It's an age"
:json-schema/example 20}
:int [:> 18]])))
;; FIXME refine
(is (= `(t/U t/Num
t/Num
t/Num)
(sut/malli-syntax->validator-type
'[:or int? pos-int? neg-int?])))
(is (thrown? clojure.lang.ExceptionInfo
(sut/malli-syntax->validator-type '[:function])))
(is (= `[t/Num :-> t/Num]
(sut/malli-syntax->validator-type
'[:function
[:=> [:cat number?] number?]])))
(is (= `(t/IFn [t/Num :-> t/Num]
[t/Num t/Num :-> t/Num])
(sut/malli-syntax->validator-type
'[:function
[:=> [:cat number?] number?]
[:=> [:cat number? number?] number?]])))
(is (= `(t/IFn [:-> t/Num]
[t/Num :-> t/Num]
[t/Num t/Num :-> t/Num])
(sut/malli-syntax->validator-type
'[:function
[:=> [:cat [:? number?]] number?]
[:=> [:cat number? number?] number?]])))
(is (= `(t/Vec t/Num)
(sut/malli-syntax->validator-type
'[:vector number?])))
(is (= `(t/Set t/Num)
(sut/malli-syntax->validator-type
'[:set number?])))
(is (= `(t/SequentialColl t/Num)
(sut/malli-syntax->validator-type
'[:sequential number?])))
(is (= `(t/Nilable t/Num)
(sut/malli-syntax->validator-type
'[:maybe number?])))
(is (= `(t/Nilable t/Num)
(sut/malli-syntax->validator-type
'[:maybe number?])))
(is (= `t/Str
(sut/malli-syntax->validator-type '[:re "foo"])
(sut/malli-syntax->validator-type '[:re #"foo"])))
(is (= `t/UUID
(sut/malli-syntax->validator-type :uuid)))
(is (thrown? clojure.lang.ExceptionInfo (sut/malli-syntax->validator-type :simple-keyword)))
(is (= `t/Kw
(sut/malli-syntax->validator-type :keyword)
(sut/malli-syntax->validator-type 'keyword?)
(sut/malli-syntax->validator-type 'simple-keyword?)
(sut/malli-syntax->validator-type :qualified-keyword)
(sut/malli-syntax->validator-type 'qualified-keyword?)))
(is (thrown? clojure.lang.ExceptionInfo (sut/malli-syntax->validator-type :simple-symbol)))
(is (= `t/Sym
(sut/malli-syntax->validator-type :symbol)
(sut/malli-syntax->validator-type 'symbol?)
(sut/malli-syntax->validator-type 'simple-symbol?)
(sut/malli-syntax->validator-type :qualified-symbol)
(sut/malli-syntax->validator-type 'qualified-symbol?)))
liquidz/merr
(ns merr.spec
(:require
[clojure.core.specs.alpha :as c.s]
[clojure.spec.alpha :as s]
[merr.core :as core]))
(s/fdef core/let
:args (s/cat :err-sym simple-symbol?
:bindings ::c.s/bindings
:body (s/* any?))
:ret any?)