Add a modify' function on extensible state

This commit is contained in:
Ruben Astudillo
2021-11-22 02:50:21 -03:00
parent 2a02fb3753
commit 282afefddf
2 changed files with 10 additions and 2 deletions

View File

@@ -77,8 +77,10 @@ workspaceHistoryHook = gets windowset >>= (XS.modify . updateLastActiveOnEachScr
-- | Like 'workspaceHistoryHook', but with the ability to exclude
-- certain workspaces.
workspaceHistoryHookExclude :: [WorkspaceId] -> X ()
workspaceHistoryHookExclude ws =
gets windowset >>= XS.modify . updateLastActiveOnEachScreenExclude ws
workspaceHistoryHookExclude ws = do
s <- gets windowset
let update' a = force (updateLastActiveOnEachScreenExclude ws s a)
XS.modify' update'
workspaceHistoryWithScreen :: X [(ScreenId, WorkspaceId)]
workspaceHistoryWithScreen = XS.gets history

View File

@@ -20,6 +20,7 @@ module XMonad.Util.ExtensibleState (
-- $usage
put
, modify
, modify'
, remove
, get
, gets
@@ -90,6 +91,11 @@ modifyStateExts f = State.modify $ \st -> st { extensibleState = f (extensibleSt
modify :: (ExtensionClass a, XLike m) => (a -> a) -> m ()
modify f = put . f =<< get
-- | Like @modify@ but the result value is applied strictly in respect to
-- the monadic environment.
modify' :: (ExtensionClass a, XLike m) => (a -> a) -> m ()
modify' f = (\a -> let res = f a in res `seq` put res) =<< get
-- | Add a value to the extensible state field. A previously stored value with the same
-- type will be overwritten. (More precisely: A value whose string representation of its type
-- is equal to the new one's)