Public Vars

Back

type (clj)

(source)

function

(type x)
Returns the :type metadata of x, or its Class if none

Examples

clojure
(deftest division
  (is (= clojure.core// /))
  (binding [*ns* *ns*]
    (eval '(do (ns foo
                 (:require [clojure.core :as bar])
                 (:use [clojure.test]))
               (is (= clojure.core// bar//))))))

(defspec types-that-should-roundtrip
  roundtrip
  [^{:tag cgen/ednable} o]
  (when-not (= o %)
    (throw (ex-info "Value cannot roundtrip, see ex-data" {:printed o :read %}))))

(defspec types-that-need-dup-to-roundtrip
  roundtrip-dup
  [^{:tag cgen/dup-readable} o]
  (when-not (= o %)
    (throw (ex-info "Value cannot roundtrip, see ex-data" {:printed o :read %}))))
babashka/babashka
(ns babashka.impl.protocols
  (:require [babashka.impl.protocols :as protocols]
            [clojure.core.protocols :as p]
            [clojure.datafy :as d]
            ;; ensure datafy is loaded, we're going to override its
            ;; clojure.lang.Namespace implementation for datafy
            [clojure.reflect]
            [sci.core :as sci :refer [copy-var]]
            [sci.impl.types :as types]
            [sci.impl.vars]))

(defmulti datafy types/type-impl)

(defmethod datafy :sci.impl.protocols/reified [x]
  (let [methods (types/getMethods x)]
    ((get methods 'datafy) x)))

;;;; nav
(defmulti nav types/type-impl)

(defmethod nav :sci.impl.protocols/reified [coll k v]
  (let [methods (types/getMethods coll)]
    ((get methods 'nav) coll k v)))
pedestal/pedestal
(ns io.pedestal.interceptor.error
  (:require [io.pedestal.interceptor :as interceptor]
            [clojure.core.match :as match]))

(defmacro error-dispatch
  "Return an interceptor for doing pattern-matched error-dispatch, based on
  the ex-data of the exception.
  Pedestal wraps *all* exceptions in ex-info on error, providing the following
  keys to match on: `:execution-id`, `:stage`, `:interceptor`, `:exception-type`

  This allows you to match the exact exception type, per interceptor/handler,
  and even constrain it to a single stage (:enter, :leave, :error).

  `:exception-type` is a keyword of the exception's type, for example,
  `:java.lang.ArithmeticException
  "
  [binding-vector & match-forms]
  `(io.pedestal.interceptor/interceptor
     {:error (fn ~binding-vector
               (clojure.core.match/match [(ex-data ~(second binding-vector))]
                  ~@match-forms))}))
nextjournal/clerk
(ns viewers.controls
  "Demo of Clerk's two-way bindings."
  {:nextjournal.clerk/visibility {:code :show :result :show}}
  (:require [clojure.core :as core]
            [nextjournal.clerk :as clerk]
            [nextjournal.clerk.viewer :as viewer]))

(def render-slider
  '(fn [state-atom]
     [:input {:type :range :value @state-atom :on-change #(swap! state-atom (constantly (int (.. % -target -value))))}]))

(def render-text-input
  '(fn [state-atom]
     [:input {:type :text :value @state-atom :on-change #(swap! state-atom (constantly (.. % -target -value)))
              :class "px-3 py-3 placeholder-blueGray-300 text-blueGray-600 relative bg-white bg-white rounded text-sm border border-blueGray-300 outline-none focus:outline-none focus:ring w-full"}]))

(def convenient-slider
  {:transform-fn (comp transform-var (clerk/update-val #(cond-> % (viewer/get-safe % ::clerk/var-from-def) ::clerk/var-from-def)))
   :render-fn '(fn [x] (let [state-atom (cond-> x (var? x) deref)]
                         [:input {:type :range :value @state-atom :on-change #(swap! state-atom (constantly (int (.. % -target -value))))}]))})
nextjournal/clerk
(ns nextjournal.clerk.atom
  "Demo of Clerk's two-way bindings."
  {:nextjournal.clerk/visibility {:code :hide :result :hide}}
  (:require [clojure.core :as core]
            [nextjournal.clerk :as clerk]))

(def slider-viewer
  {:render-fn '(fn [x] [:input {:type :range :value (:counter @@(resolve x)) :on-change #(swap! @(resolve x) assoc :counter (int (.. % -target -value)))}])
   :transform-fn transform-var})
cognitect-labs/aws-api
(ns s3-examples
  (:require [clojure.core.async :as a]
            [clojure.spec.alpha :as s]
            [clojure.spec.gen.alpha :as gen]
            [clojure.java.io :as io]
            [clojure.repl :as repl]
            [cognitect.aws.client.api :as aws]))

  ;; Body is blob type, for which we accept a byte-array or an InputStream
  (aws/invoke s3 {:op :PutObject :request {:Bucket bucket-name :Key "hello.txt"
                                           :Body (.getBytes "Oh hai!")}})

  ;; Body is a blob type, which always returns an InputStream
  (aws/invoke s3 {:op :GetObject :request {:Bucket bucket-name :Key "hello.txt"}})