Public Vars

Back

extend-type (clj)

(source)

macro

(extend-type t & specs)
A macro that expands into an extend call. Useful when you are supplying the definitions explicitly inline, extend-type automatically creates the maps required by extend. Propagates the class as a type hint on the first argument of all fns. (extend-type MyType Countable (cnt [c] ...) Foo (bar [x y] ...) (baz ([x] ...) ([x y & zs] ...))) expands into: (extend MyType Countable {:cnt (fn [c] ...)} Foo {:baz (fn ([x] ...) ([x y & zs] ...)) :bar (fn [x y] ...)})

Examples

jonase/eastwood
(ns testcases.unusednss3
  (:require [clojure.core.protocols :as protocols]
            [clojure.core.reducers  :as reducers]
            [clojure.data           :as data]
            [clojure.java.io        :as io]
            [clojure.reflect        :as reflect]))

(extend-type String
  data/EqualityPartition
  (equality-partition [x] nil))
immutant/immutant
(ns immutant.caching.core-cache
  "Require this to extend `org.infinispan.Cache` to the
  [core.cache](https://github.com/clojure/core.cache) `CacheProtocol`"
  (:require [clojure.core.cache :as core])
  (:import org.infinispan.Cache))

(extend-type org.infinispan.Cache
  core/CacheProtocol
  (lookup
    ([this key]
       (.get this key))
    ([this key not-found]
       (if (.containsKey this key)
               (.get this key)
               not-found)))
  (has? [this key]
    (.containsKey this key))
  (hit [this key]
    this)
  (miss [this key value]
    (.put this key value)
    this)
  (evict [this key]
    (.remove this key)
    this)
  (seed [this base]
    (.clear this)
    (when base (.putAll this base))
    this))
replikativ/replikativ
(ns replikativ.crdt.lwwr.impl
  (:require [replikativ.protocols :refer [POpBasedCRDT -downstream
                                          PExternalValues -missing-commits
                                          PPullOp -pull]]
            [replikativ.crdt.lwwr.core :refer [downstream]]
            #?(:clj [superv.async :refer [go-try go-loop-try <?]])
            #?(:clj [clojure.core.async :as async
                    :refer [>! timeout chan put! pub sub unsub close!]]
               :cljs [cljs.core.async :as async
                      :refer [>! timeout chan put! pub sub unsub close!]]))
  #?(:cljs (:require-macros [superv.async :refer [go-try go-loop-try <?]])))

(extend-type replikativ.crdt.LWWR
  POpBasedCRDT
  (-handshake [this S] (into {} this))
  (-downstream [this op] (downstream this op))
  PExternalValues
  (-missing-commits [this S store out fetched-ch op] (go-try S #{})))
lambda-toolshed/papillon
(ns lambda-toolshed.papillon.async
  #?(:cljs
     (:require [clojure.core.async :as core.async]
               [clojure.core.async.impl.protocols :refer [ReadPort]]
               [cljs.core.async.interop :as core.async.interop :refer [p->c]])))

#?(:cljs
   (do
     (extend-type js/Promise
       ReadPort
       (take! [this handler]
         (->
          this
          p->c
          (#(core.async/take 1 %))
          (clojure.core.async.impl.protocols/take! handler))))))
r0man/netcdf-clj
(ns netcdf.datafy
  (:require [clojure.core.protocols :refer [Datafiable]]
            [clojure.datafy :refer [datafy]]))

(extend-type ucar.ma2.DataType
  Datafiable
  (datafy [data-type]
    (keyword (str data-type))))

(extend-type ucar.nc2.Attribute
  Datafiable
  (datafy [attribute]
    {:name (.getName attribute)
     :values (mapv #(.getValue attribute %) (range (.getLength attribute)))}))

(extend-type ucar.nc2.dataset.CoordinateSystem
  Datafiable
  (datafy [coordinate-system]
    {:name (.getName coordinate-system)
     :projection (datafy (.getProjection coordinate-system))}))

(extend-type ucar.nc2.dataset.NetcdfDataset
  Datafiable
  (datafy [dataset]
    {:convention (.getConventionUsed dataset)
     :global-attributes (mapv datafy (.getGlobalAttributes dataset))
     :variables (mapv datafy (.getVariables dataset))}))

(extend-type ucar.nc2.dataset.VariableDS
  Datafiable
  (datafy [variable]
    {:coordinate-systems (mapv datafy (.getCoordinateSystems variable))
     :data-type (datafy (.getDataType variable))
     :dataset-location (.getDatasetLocation variable)
     :description (.getDescription variable)
     :dimensions (mapv datafy (.getDimensions variable))
     :fill-value (.getFillValue variable)
     :missing-values (.getMissingValues variable)
     :name (.getName variable)
     :size (.getSize variable)
     :units (.getUnitsString variable)}))

(extend-type ucar.nc2.Dimension
  Datafiable
  (datafy [dimension]
    {:length (.getLength dimension)
     :name (.getName dimension)}))

(extend-type ucar.unidata.geoloc.Projection
  Datafiable
  (datafy [projection]
    {:name (.getName projection)
     :params (mapv datafy (.getProjectionParameters projection))}))

(extend-type ucar.unidata.util.Parameter
  Datafiable
  (datafy [parameter]
    (cond-> {:name (.getName parameter)}
      (.isString parameter)
      (assoc :values [(.getStringValue parameter)])
      (not (.isString parameter))
      (assoc :values (.getNumericValues parameter)))))