Pure WS monad
This commit is contained in:
parent
5d3dced6f7
commit
865b69e799
12 changed files with 346 additions and 221 deletions
|
@ -4,10 +4,12 @@ module Types.RoomsState
|
|||
HasRoomsState (..),
|
||||
roomStateDiffers,
|
||||
updateRoomState,
|
||||
getRoomState,
|
||||
)
|
||||
where
|
||||
|
||||
import ClassyPrelude
|
||||
import State.RoomDataState (MonadRoomDataStateRead (getRoomDataState))
|
||||
import Types.RoomData (RoomsData)
|
||||
|
||||
type RoomsState = MVar RoomsData
|
||||
|
@ -30,16 +32,23 @@ updateRoomState newData = do
|
|||
_ <- swapMVar state newData
|
||||
return ()
|
||||
|
||||
roomStateDiffers ::
|
||||
getRoomState ::
|
||||
( HasRoomsState env,
|
||||
MonadIO m,
|
||||
MonadReader env m
|
||||
) =>
|
||||
m RoomsData
|
||||
getRoomState = do
|
||||
state <- getRoomsState <$> ask
|
||||
readMVar state
|
||||
|
||||
roomStateDiffers ::
|
||||
( MonadRoomDataStateRead m
|
||||
) =>
|
||||
RoomsData ->
|
||||
m Bool
|
||||
roomStateDiffers newData = do
|
||||
currentData <- ask >>= readMVar . getRoomsState
|
||||
return $ not $ eqIgnoreOrdering newData currentData
|
||||
not . eqIgnoreOrdering newData <$> getRoomDataState
|
||||
|
||||
eqIgnoreOrdering :: (Eq a) => [a] -> [a] -> Bool
|
||||
eqIgnoreOrdering a b = length a == length b && all (`elem` b) a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue