Public Vars

Back

hash-map (clj)

(source)

function

(hash-map) (hash-map & keyvals)
keyval => key val Returns a new hash map with supplied mappings. If any keys are equal, they are handled as if by repeated uses of assoc.

Examples

uncomplicate/fluokitten
(ns uncomplicate.fluokitten.articles.fluokitten-extensions-clojure-core-test
  "These expressions are used as examples in the
    Fluokitten Extensions of Clojure Core
    article at the Fluokitten web site."
  (:use [uncomplicate.fluokitten jvm core test utils])
  (:require [clojure.core.reducers :as r])
  (:use [midje.sweet :exclude [just]]))

 (bind {:a 1 :b 2 :c 3} #(hash-map :increment (inc %)))
 => {[:a :increment] 2 [:b :increment] 3 [:c :increment] 4}
typedclojure/typedclojure
(ns typed.clojure.jvm
  "JVM-specific annotations and operations.
  See typed.clojure for cross-platform ops."
  (:require clojure.core.typed
            [clojure.core.typed.current-impl :as impl]
            [clojure.core.typed.internal :refer [take-when]]
            [typed.cljc.runtime.env-utils :refer [delay-type]]
            [clojure.core.typed.macros :as macros]))

(defmacro override-class [& args]
  (let [[binder args] (take-when vector? args)
        [nme args] (take-when symbol? args)
        _ (assert (symbol? nme) (str "Missing name in override-class" [nme args]))
        [opts args] (take-when map? args)
        opts (if opts
               (do (assert (empty? args) (str "Trailing args to override-class: " (pr-str args)))
                   opts)
               (apply hash-map args))
        this-ns (ns-name *ns*)]
    `(clojure.core.typed/tc-ignore
       (let [nme# (or (when-some [^Class c# (ns-resolve '~this-ns '~nme)]
                        (when (class? c#)
                          (-> c# .getName symbol)))
                      (throw (ex-info (str "Could not resolve class: " '~nme) {:class-name '~nme})))]
          ;; TODO runtime env
         #_
         (impl/add-rclass-env nme# {:op :RClass})
         ;; type env
         ;inline when-bindable-defining-ns
         (macros/when-bindable-defining-ns '~this-ns
           (impl/with-clojure-impl
             (impl/add-rclass nme# (delay-type
                                     ((requiring-resolve 'typed.clj.checker.parse-unparse/with-parse-ns*)
                                      '~this-ns
                                      #((requiring-resolve 'typed.cljc.checker.base-env-helper/make-RClass)
                                        nme#
                                        '~binder
                                        '~opts))))))))))
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)]))
ReactiveX/RxClojure
(ns rx.lang.clojure.blocking-test
  (:require [rx.lang.clojure.blocking :as b]
            [rx.lang.clojure.core :as rx]
            [clojure.test :refer [deftest testing is]]))

(deftest test-doseq
  (is (= (range 3)
         (let [capture (atom [])]
           (b/doseq [{:keys [value]} (rx/seq->o (map #(hash-map :value %) (range 3)))]
             (println value)
             (swap! capture conj value))
           @capture)))
ReactiveX/RxClojure
(ns rx.lang.clojure.realized-test
  (:require [rx.lang.clojure.realized :as r]
            [rx.lang.clojure.core :as rx]
            [rx.lang.clojure.future :as rx-future]
            [rx.lang.clojure.blocking :as rx-blocking]
            [clojure.test :refer [deftest testing is]]))

  (->> (get-list-of-lists user-id)
       (rx/mapcat (fn [list]
                    (->> (video-list->videos list)
                         (rx/take 10))))
       (rx/mapcat (fn [video]
                    (->> (r/realized-map :id (:id video)
                                            :md [(video->metadata video)
                                                 first
                                                 #(select-keys % [:title :duration])]
                                            :bookmark (video->bookmark video)
                                            :rating [(video->rating video user-id)
                                                     first
                                                     #(hash-map :actual (:actual-star-rating %)
                                                                :average (:average-star-rating %)
                                                                :predicted (:predicted-star-rating %))])
                         (rx/map (fn [m]
                                   (-> m
                                       (merge (:md m))
                                       (dissoc :md)))))))))