module Prelate.Atomic where

import Incipit (AtomicState, Member, Sem, atomicGets, atomicModify')
import Lens.Micro (Lens', (.~))
import Lens.Micro.Extras (view)

atomicSet ::
  Member (AtomicState s) r =>
  Lens' s a ->
  a ->
  Sem r ()
atomicSet :: forall s (r :: EffectRow) a.
Member (AtomicState s) r =>
Lens' s a -> a -> Sem r ()
atomicSet Lens' s a
l a
a =
  (s -> s) -> Sem r ()
forall s (r :: EffectRow).
Member (AtomicState s) r =>
(s -> s) -> Sem r ()
atomicModify' ((a -> Identity a) -> s -> Identity s
Lens' s a
l ((a -> Identity a) -> s -> Identity s) -> a -> s -> s
forall s t a b. ASetter s t a b -> b -> s -> t
.~ a
a)

atomicView ::
  Member (AtomicState s) r =>
  Lens' s a ->
  Sem r a
atomicView :: forall s (r :: EffectRow) a.
Member (AtomicState s) r =>
Lens' s a -> Sem r a
atomicView Lens' s a
l =
  (s -> a) -> Sem r a
forall s s' (r :: EffectRow).
Member (AtomicState s) r =>
(s -> s') -> Sem r s'
atomicGets (Getting a s a -> s -> a
forall a s. Getting a s a -> s -> a
view Getting a s a
Lens' s a
l)