Public Vars

Back

dissoc! (clj)

(source)

function

(dissoc! map key) (dissoc! map key & ks)
Returns a transient map that doesn't contain a mapping for key(s).

Examples

wilkerlucio/pathom3
(ns com.wsscode.pathom3.interface.smart-map-test
  (:require
    [clojure.core.protocols :as d]
    [clojure.test :refer [deftest is are run-tests testing]]
    [com.wsscode.pathom3.connect.built-in.resolvers :as pbir]
    [com.wsscode.pathom3.connect.indexes :as pci]
    [com.wsscode.pathom3.connect.operation :as pco]
    [com.wsscode.pathom3.entity-tree :as p.ent]
    [com.wsscode.pathom3.interface.smart-map :as psm]
    [com.wsscode.pathom3.test.geometry-resolvers :as geo]
    [com.wsscode.pathom3.test.helpers :as th]
    [matcher-combinators.test])
  #?(:clj
     (:import
       (clojure.lang
         ExceptionInfo))))

(deftest sm-dissoc!-test
  (testing "uses source context on the new smart map"
    (let [sm (psm/smart-map (pci/register registry)
               {:x 3 :width 5})]
      (is (= (:right sm) 8))
      (is (= (:right (psm/sm-dissoc! sm :width)) 8)))))
replikativ/replikativ
(ns replikativ.ormap-test
  (:require [clojure.test :refer :all]
            [replikativ.environ :refer [*date-fn*]]
            [superv.async :refer [<?? S]]
            [clojure.core.async :refer [timeout]]
            [kabel.peer :refer [start stop]]
            [konserve
             [filestore :refer [new-fs-store]]
             [memory :refer [new-mem-store]]]
            [replikativ
             [peer :refer [client-peer]]
             [stage :refer [connect! create-stage!]]]
            [replikativ.crdt.ormap.stage :as ors]
            [replikativ.crdt.ormap.realize :as real]))


(deftest ormap-stage-test
  (testing "ormap operations"
    (let [user "mail:prototype@your-domain.com"
          ormap-id #uuid "12345678-be95-4700-8150-66e4651b8e46"
          store (<?? S (new-mem-store))
          peer (<?? S (client-peer S store))
          stage (<?? S (create-stage! user peer))
          _ (<?? S (ors/create-ormap! stage
                                    :id ormap-id
                                    :description "some or map"
                                    :public false))]
      (is (= (get-in @stage [user ormap-id :downstream :crdt]) :ormap))
      (binding [*date-fn* (constantly 0)]
        (<?? S (ors/assoc! stage [user ormap-id] :me [['set-person {:name "Hal"}]])))
      (is (= (map #(dissoc % :uid) (<?? S (ors/get stage [user ormap-id] :me)))
             [{:transactions [['set-person {:name "Hal"}]],
               :ts 0,
               :author "mail:prototype@your-domain.com",
               :version 1,
               :crdt :ormap}]))
      (<?? S (ors/dissoc! stage [user ormap-id] :me [['remove-person {:name "Hal"}]]))
      (is (= (<?? S (ors/get stage [user ormap-id] :me)) nil))
      (stop peer))))

(deftest ormap-streaming
  (testing "ormap stream into identity"
    (let [user "mail:prototype@your-domain.com"
          ormap-id #uuid "12345678-be95-4700-8150-66e4651b8e46"
          store (<?? S (new-mem-store))
          peer (<?? S (client-peer S store))
          stage (<?? S (create-stage! user peer))
          val-atom (atom {})
          eval-fn {'set-person (fn [S old [k v]]
                                  (swap! old assoc k v)
                                  old)
                   'remove-person (fn [S old k]
                                     (swap! old dissoc k)
                                     old)}
          close-stream (real/stream-into-identity! stage [user ormap-id] eval-fn val-atom
                                                   :conflict-cb
                                                   (fn [cs] (is (= cs
                                                                   {"Hal"
                                                                    #{#uuid "275b3aed-818c-5f1b-9667-a51f5fc7f043"
                                                                      #uuid "1f8c5b27-21d2-5b82-aab8-087784ee8903"}}))))
          _ (<?? S (ors/create-ormap! stage
                                      :id ormap-id
                                      :description "some or map"
                                      :public false))]
      (is (= (get-in @stage [user ormap-id :downstream :crdt]) :ormap))
      (binding [*date-fn* (constantly 0)]
        (<?? S (ors/assoc! stage [user ormap-id] "Hal" [['set-person ["Hal" {:name "Hal"}]]])))
      (is (= (map #(dissoc % :uid) (<?? S (ors/get stage [user ormap-id] "Hal")))
             [{:transactions [['set-person ["Hal" {:name "Hal"}]]],
               :ts 0,
               :author "mail:prototype@your-domain.com",
               :version 1,
               :crdt :ormap}]))
      (<?? S (timeout 100))
      (is (= (get @val-atom "Hal") {:name "Hal"}))
      (<?? S (ors/dissoc! stage [user ormap-id] "Hal" [['remove-person "Hal"]]))
      (<?? S (timeout 100))
      (is (= (<?? S (ors/get stage [user ormap-id] "Hal")) nil))

(<?? (ors/or-dissoc! stage-a [user-a ormap-id] 12 [['- 42]]))
replikativ/replikativ
(ns replikativ.merging-ormap-test
  (:require  [clojure.test :refer :all]
             [replikativ.crdt.merging-ormap.core :refer :all]
             [replikativ.environ :refer [*date-fn*]]
             [superv.async :refer [<?? S]]
             [clojure.core.async :refer [timeout]]
             [kabel.peer :refer [start stop]]
             [konserve
              [filestore :refer [new-fs-store]]
              [memory :refer [new-mem-store]]]
             [replikativ
              [peer :refer [client-peer server-peer]]
              [stage :refer [connect! create-stage!]]]
             [replikativ.crdt.merging-ormap.stage :as mors]
             #_[replikativ.crdt.ormap.realize :as real]))


(deftest merging-ormap-stage-test
  (testing "merging ormap operations"
    (let [user "mail:prototype@your-domain.com"
          mormap-id #uuid "12345678-be95-4700-8150-66e4651b8e46"
          store (<?? S (new-mem-store))
          peer (<?? S (client-peer S store))
          stage (<?? S (create-stage! user peer))
          _ (<?? S (mors/create-merging-ormap! stage 'max max
                                               :id mormap-id
                                               :description "some or merging map"
                                               :public false))]
      (is (= (get-in @stage [user mormap-id :downstream :crdt]) :merging-ormap))
      (<?? S (mors/assoc! stage [user mormap-id] :me 42))
      (<?? S (mors/assoc! stage [user mormap-id] :me 43))
      (is (= (<?? S (mors/get stage [user mormap-id] :me)) 43))
      (<?? S (timeout 1000))
      (is (= (<?? S (mors/get stage [user mormap-id] :me)) 43))
      (<?? S (mors/dissoc! stage [user mormap-id] :me))
      (is (= (<?? S (mors/get stage [user mormap-id] :me)) nil))
      (stop peer))))

          _ (<?? S (mors/create-merging-ormap! stage-a 'max max
                                               :id mormap-id
                                               :description "some or merging map"
                                               :public false))
          _ (<?? S (mors/create-merging-ormap! stage-b 'max max
                                               :id mormap-id
                                               :description "some or merging map"
                                               :public false))]
      (<?? S (start peer-a))
      (<?? S (timeout 1000))
      (<?? S (connect! stage-b uri))
      (is (= (get-in @stage-a [user mormap-id :downstream :crdt]) :merging-ormap))
      (<?? S (mors/assoc! stage-a [user mormap-id] :me 42))
      (<?? S (mors/assoc! stage-b [user mormap-id] :me 43))
      (<?? S (timeout 1000))
      (is (= (<?? S (mors/get stage-a [user mormap-id] :me)) 43))
      (is (= (<?? S (mors/get stage-b [user mormap-id] :me)) 43))
      (<?? S (mors/dissoc! stage-a [user mormap-id] :me))
      (<?? S (timeout 1000))
      (is (= (<?? S (mors/get stage-a [user mormap-id] :me)) nil))
      (is (= (<?? S (mors/get stage-b [user mormap-id] :me)) nil))
      (stop peer-a)
      (stop peer-b))))
luminus-framework/expiring-map
(ns expiring-map.benchmark
  (:require [clojure.test :refer :all]
            [criterium.core :as criterium]
            [clojure.core.cache :refer [ttl-cache-factory]]
            [expiring-map.core :as em]))

  (println "++++ expiring-map assoc!/dissoc!")
  (let [cache (em/expiring-map 1 {:time-unit :hours})
        value {:bar "baz" :baz [1 2 3 {:foo "bar"}]}]
    (criterium/quick-bench
     (do
       (em/assoc! cache :foo value)
       (em/dissoc! cache :foo))))
replikativ/twitter-collector
(ns twitter-collector.ormap
  (:require [twitter-collector.core :refer [user cdvcs-id]]
            [replikativ.crdt.ormap.realize :as rors]
            [replikativ.peer :refer [client-peer]]
            [replikativ.p2p.fetch :refer [fetch]]
            [replikativ.stage :refer [create-stage! connect!]]
            [replikativ.crdt.cdvcs.stage :as cs]
            [replikativ.crdt.ormap.stage :as ors]
            [konserve.filestore :refer [new-fs-store]]
            [konserve.memory :refer [new-mem-store]]
            [clojure.core.async :as async]
            [superv.async :refer [<?? S]]
            [replikativ.stage :as s]
            [konserve.core :as k]
            [replikativ.crdt.cdvcs.stage :as cs]
            [datomic.api :as d]
            [taoensso.timbre :as timbre]))

(time
 (doseq [i (range 10000)]
   (<?? S (ors/dissoc! client-stage [user ormap-id] i [['- i]]))))