Back
vary-meta (clj)
(source)function
(vary-meta obj f & args)
Returns an object of the same type and value as obj, with
(apply f (meta obj) args) as its metadata.
Examples
typedclojure/typedclojure
In general these operations:
- are macros instead of functions
- take Typed Clojure types instead of malli schemas
- helps the type checker infer their results
See also:
- typed.malli.generator
- typed.malli.swagger
- typed.malli.json-schema"
(:require [typed.clojure :as t]
[clojure.core.typed.unsafe :as unsafe]
[malli.core :as m]))
eg.,
(defvalidator AnyInteger? t/AnyInteger)
(AnyInteger? 1) => true
(AnyInteger? nil) => false"
[name t]
`(do (t/ann ~(vary-meta name assoc :no-check true) [t/Any :-> t/Bool
:filters {:then (~'is ~t 0)
:else (~'! ~t 0)}])
(def ~name (validator ~t))))
(defmacro defparser
"Def parser for Typed Clojure type t. Type checker infers
the type of the return value when used.
eg.,
(defparser AnyInteger-parser t/AnyInteger)
(AnyInteger-parser 1) ;=> 1
(AnyInteger-parser nil) ;=> :malli.core/invalid"
[name t]
`(do (t/ann ~(vary-meta name assoc :no-check true)
[t/Any :-> (t/U (t/Val ::m/invalid)
~(-> t
((requiring-resolve 'typed.malli.parse-type/type-syntax->malli-syntax))
((requiring-resolve 'typed.malli.schema-to-type/malli-syntax->parser-type))))])
(def ~name (parser ~t))))
(defmacro defunparser
[name t]
`(do (t/ann ~(vary-meta name assoc :no-check true)
[t/Any :-> ~t])
(def ~name (unparser ~t))))
typedclojure/typedclojure
(ns ^:no-doc typed.clj.ext.clojure.core__reify
"Typing rules clojure.core/reify"
(:require [clojure.core.typed.internal :as internal]
[typed.cljc.checker.check :as chk]
[typed.cljc.analyzer :as ana2]
[typed.cljc.checker.check.unanalyzed :refer [defuspecial]]))
(defuspecial defuspecial__reify
"defuspecial implementation for clojure.core/reify"
[{original-reify-form :form :as original-expr} expected]
(-> original-expr
ana2/analyze-outer
((fn [expr]
{:pre [(= :unanalyzed (:op expr))]
:post [(= :unanalyzed (:op %))]}
(update expr :form (fn [form]
{:pre [(= 'reify* (first form))]}
(-> (list* (vary-meta (first form) assoc ::original-reify-expr original-expr)
(rest form))
(with-meta (meta form)))))))
(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))))
cc/associative? (t/Pred (t/Associative t/Any t/Any))
cc/coll? (t/Pred (t/Coll t/Any))
;TODO should these be parameterized?
cc/sequential? (t/Pred t/Sequential)
cc/sorted? (t/Pred (t/Sorted t/Any))
cc/meta [t/Any :-> (t/Nilable (t/Map t/Any t/Any))]
;; FIXME IObj annotations are a hack. doesn't literally return the same reference.
cc/with-meta (t/All [[x :< #?(:clj clojure.lang.IObj
:cljs cljs.core/IWithMeta)]]
[x (t/Nilable (t/Map t/Any t/Any)) :-> x])
cc/vary-meta (t/All [[x :< #?(:clj clojure.lang.IObj
:cljs cljs.core/IWithMeta)] b :..]
[x [(t/Nilable (t/Map t/Any t/Any)) b :.. b :-> (t/Nilable (t/Map t/Any t/Any))] b :.. b :-> x])
camsaul/methodical
(ns methodical.impl.dispatcher.everything
(:refer-clojure :exclude [methods])
(:require
[clojure.core.protocols :as clojure.protocols]
[methodical.impl.dispatcher.common :as dispatcher.common]
[methodical.interface :as i]
[methodical.util.describe :as describe]
[pretty.core :as pretty])
(:import
(methodical.interface Dispatcher)))
(matching-primary-methods [_ method-table _]
(let [primary-methods (i/primary-methods method-table)
comparatorr (dispatcher.common/domination-comparator (deref hierarchy-var) prefs)]
(for [[dispatch-value method] (sort-by first comparatorr primary-methods)]
(vary-meta method assoc :dispatch-value dispatch-value))))
(matching-aux-methods [_ method-table _]
(let [aux-methods (i/aux-methods method-table)
comparatorr (dispatcher.common/domination-comparator (deref hierarchy-var) prefs)]
(into {} (for [[qualifier dispatch-value->methods] aux-methods]
[qualifier (for [[dispatch-value methods] (sort-by first comparatorr dispatch-value->methods)
method methods]
(vary-meta method assoc :dispatch-value dispatch-value))]))))