1 {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
3 module RMCA.ReactiveValueAtomicUpdate where
7 import Data.ReactiveValue
9 class (ReactiveValueReadWrite a b m) => ReactiveValueAtomicUpdate a b m where
10 reactiveValueUpdate :: a -> (b -> b) -> m b
12 reactiveValueAppend :: (Monoid b, ReactiveValueAtomicUpdate a b m) =>
14 reactiveValueAppend rv val = void $ reactiveValueUpdate rv (`mappend` val)
16 reactiveValueEmpty :: (Monoid b, ReactiveValueAtomicUpdate a b m) =>
18 reactiveValueEmpty rv = reactiveValueUpdate rv (\_ -> mempty)
20 instance ReactiveValueRead (CBRef a) a IO where
21 reactiveValueRead = readCBRef
22 reactiveValueOnCanRead = installCallbackCBRef
24 instance ReactiveValueWrite (CBRef a) a IO where
25 reactiveValueWrite = writeCBRef
27 instance ReactiveValueReadWrite (CBRef a) a IO where
29 instance ReactiveValueAtomicUpdate (CBRef a) a IO where
30 reactiveValueUpdate rv f = atomicModifyCBRef rv (\x -> (f x, x))