Public Vars

Back

volatile! (clj)

(source)

function

(volatile! val)
Creates and returns a Volatile with an initial value of val.

Examples

uncomplicate/fluokitten
(ns uncomplicate.fluokitten.core-test
  (:use [uncomplicate.fluokitten algo jvm core test utils])
  (:use [midje.sweet :exclude [just]])
  (:require [clojure.string :as s]
            [clojure.core.reducers :as r]))

(functor-law2 inc (partial * 100) (volatile! 34))

(functor-law2 inc (partial * 100) (volatile! 35) (volatile! 5))

(fmap-keeps-type inc (volatile! 36))

(fmap-keeps-type + (volatile! 37) (volatile! 5))

(applicative-law1 inc (volatile! 6))

(applicative-law1 + (volatile! 6) (volatile! 9) (volatile! -77) (volatile! -1))

(applicative-law2-identity (volatile! 6))

(applicative-law3-composition (volatile! inc) (volatile! (partial * 10)) (volatile! 6))

(applicative-law3-composition (volatile! inc) (volatile! (partial * 10)) (volatile! 6) (volatile! -2))

(applicative-law4-homomorphism (volatile! 6) inc 5)

(applicative-law4-homomorphism (volatile! 6) + 5 -4 5)

(applicative-law5-interchange (volatile! 6) inc 5)

(applicative-law5-interchange (volatile! 6) + 5 3 4 5)

(facts "Join function for volatiles."
       (join (volatile! 1)) => (check-eq (volatile! 1))
       (join (volatile! (volatile! 2))) => (check-eq (volatile! 2)))

(monad-law1-left-identity (volatile! 9) (comp volatile! inc) 1)

(monad-law1-left-identity (volatile! 9) (comp volatile! +) 1 2 3)

(monad-law2-right-identity (volatile! 9))

(monad-law3-associativity (comp volatile! inc) (comp volatile! (partial * 10)) (volatile! 9))

(extract-is-dual-of-pure [0] 1)
(extract-is-dual-of-pure (double-array [0]) 1.0)
(extract-is-dual-of-pure (list 0) 1)
(extract-is-dual-of-pure (reducible []) 1)
(extract-is-dual-of-pure (lazy-seq []) 1)
(extract-is-dual-of-pure (eduction []) 1)
(extract-is-dual-of-pure (seq []) 1)
(extract-is-dual-of-pure #{0} 1)
(extract-is-dual-of-pure {:a :b} 1)
(extract-is-dual-of-pure (first {:a :b}) 1)
(extract-is-dual-of-pure (atom 0) 1)
(extract-is-dual-of-pure (ref 0) 1)
(extract-is-dual-of-pure (volatile! 0) 1)
(extract-is-dual-of-pure + 1)
(extract-is-dual-of-pure (just 0) 1)

(magma-op-keeps-type (volatile! 1) (volatile! 2))

(magma-op-keeps-type (volatile! 2) (volatile! 3) (volatile! 4))

(semigroup-op-associativity (volatile! 5) (volatile! 6))

(semigroup-op-associativity (volatile! 7) (volatile! 8) (volatile! 9))

(monoid-identity-law (volatile! 4))
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/volatile! (t/All [x] [x :-> (t/Volatile x)])