1 {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
3 module RMCA.ReactiveValueAtomicUpdate where
7 import Data.ReactiveValue
9 reactiveValueNonAtomicUpdate :: (ReactiveValueReadWrite a b m) =>
11 reactiveValueNonAtomicUpdate rv f = do
12 val <- reactiveValueRead rv
13 reactiveValueWrite rv $ f val
16 class (ReactiveValueReadWrite a b m) => ReactiveValueAtomicUpdate a b m where
17 reactiveValueUpdate :: a -> (b -> b) -> m b
19 reactiveValueAppend :: (Monoid b, ReactiveValueAtomicUpdate a b m) =>
21 reactiveValueAppend rv val = void $ reactiveValueUpdate rv (`mappend` val)
23 reactiveValueEmpty :: (Monoid b, ReactiveValueAtomicUpdate a b m) =>
25 reactiveValueEmpty rv = reactiveValueUpdate rv (const mempty)
27 instance ReactiveValueRead (CBRef a) a IO where
28 reactiveValueRead = readCBRef
29 reactiveValueOnCanRead = installCallbackCBRef
31 instance ReactiveValueWrite (CBRef a) a IO where
32 reactiveValueWrite = writeCBRef
34 instance ReactiveValueReadWrite (CBRef a) a IO where
36 instance ReactiveValueAtomicUpdate (CBRef a) a IO where
37 reactiveValueUpdate rv f = atomicModifyCBRef rv (\x -> (f x, x))