Public Vars

Back

array-map (clj)

(source)

function

(array-map) (array-map & keyvals)
Constructs an array-map. If any keys are equal, they are handled as if by repeated uses of assoc.

Examples

clojure/core.typed
;copied from clojure.tools.analyzer.passes.constant-lifter
(ns clojure.core.typed.analyzer.common.passes.constant-lifter
  (:require [clojure.core.typed.analyzer.common :as common]
            [clojure.core.typed.analyzer.common.utils :refer [const-val]]))

(defmethod constant-lift :map
  [{:keys [keys vals form env] :as ast}]
  (if (and (every? :literal? keys)
           (every? :literal? vals)
           (empty? (meta form)))
    (let [c (into (empty form)
                  (zipmap (mapv const-val keys)
                          (mapv const-val vals)))
          c (if (= (class c) (class form))
              c
              (apply array-map (mapcat identity c)))]
      (merge (dissoc ast :keys :vals :children)
             {:op       :const
              ::common/op ::common/const
              :val      c
              :type     :map
              :literal? true}))
    ast))
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/set (t/All [x] [(t/Seqable x) :-> #?(:cljs (t/Set x)
                                        :default (PersistentHashSet x))])
cc/hash-set (t/All [x] [x :* :-> #?(:cljs (t/Set x)
                                    :default (PersistentHashSet x))])
;TODO
;cc/hash-map (t/All [x y z :..]
;                   (t/IFn [(t/cat z z) :.. z :-> (t/Assoc '{} z :.. z)]
;                          [(t/cat x y) :* :-> (t/Map x y)]))
cc/hash-map (t/All [x y] [(t/cat x y) :* :-> (t/Map x y)])
cc/array-map (t/All [x y] [(t/cat x y) :* :-> (t/Map x y)])
cc/sorted-map (t/All [x y] [(t/cat x y) :* :-> (t/SortedMap x y)])
cc/sorted-map-by (t/All [x y] [[x x :-> t/Int] (t/cat x y) :* :-> (t/SortedMap x y)])
cc/sorted-set (t/All [x] [x :* :-> (t/SortedSet x)])
;;FIXME use t/Comparator for first arg
cc/sorted-set-by (t/All [x] [[x x :-> t/Int] x :* :-> (t/SortedSet x)])
cc/list (t/All [x] [x :* :-> (#?(:clj PersistentList :cljs t/List) x)])
;cc/list* (t/All [x] [x :* (t/Seqable x) :-> (t/NilableNonEmptyASeq x)])
cc/list* (t/All [x] (t/IFn [(t/Seqable x) :-> (t/NilableNonEmptyASeq x)]
                           [x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
                           [x x x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]))