mirror of
https://github.com/xmonad/xmonad.git
synced 2025-08-10 09:01:52 -07:00
Add StackSet.filter
This commit is contained in:
17
StackSet.hs
17
StackSet.hs
@@ -76,12 +76,13 @@
|
|||||||
module StackSet (
|
module StackSet (
|
||||||
StackSet(..), Workspace(..), Screen(..), Stack(..), RationalRect(..),
|
StackSet(..), Workspace(..), Screen(..), Stack(..), RationalRect(..),
|
||||||
new, view, lookupWorkspace, peek, index, integrate, focusUp, focusDown,
|
new, view, lookupWorkspace, peek, index, integrate, focusUp, focusDown,
|
||||||
focusWindow, member, findIndex, insertUp, delete, shift,
|
focusWindow, member, findIndex, insertUp, delete, shift, filter,
|
||||||
swapMaster, swapUp, swapDown, modify, float, sink -- needed by users
|
swapMaster, swapUp, swapDown, modify, float, sink -- needed by users
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Prelude hiding (filter)
|
||||||
import Data.Maybe (listToMaybe)
|
import Data.Maybe (listToMaybe)
|
||||||
import qualified Data.List as L (delete,find,genericSplitAt)
|
import qualified Data.List as L (delete,find,genericSplitAt,filter)
|
||||||
import qualified Data.Map as M (Map,insert,delete,empty)
|
import qualified Data.Map as M (Map,insert,delete,empty)
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
@@ -261,6 +262,18 @@ integrate :: Stack a -> [a]
|
|||||||
integrate Empty = []
|
integrate Empty = []
|
||||||
integrate (Node x l r) = reverse l ++ x : r
|
integrate (Node x l r) = reverse l ++ x : r
|
||||||
|
|
||||||
|
-- |
|
||||||
|
-- /O(n)/. 'filter p s' returns the elements of 's' such that 'p' evaluates to
|
||||||
|
-- True. Order is preserved, and focus moves to the next node to the right (if
|
||||||
|
-- necessary).
|
||||||
|
filter :: (a -> Bool) -> Stack a -> Stack a
|
||||||
|
filter p Empty = Empty
|
||||||
|
filter p (Node f ls rs) = case L.filter p (f:rs) of
|
||||||
|
(f':rs') -> Node f' (L.filter p ls) rs'
|
||||||
|
[] -> case reverse $ L.filter p ls of
|
||||||
|
[] -> Empty
|
||||||
|
(f':rs') -> Node f' [] rs'
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- /O(s)/. Extract the stack on the current workspace, as a list.
|
-- /O(s)/. Extract the stack on the current workspace, as a list.
|
||||||
-- The order of the stack is determined by the master window -- it will be
|
-- The order of the stack is determined by the master window -- it will be
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{-# OPTIONS -fglasgow-exts #-}
|
{-# OPTIONS -fglasgow-exts #-}
|
||||||
|
|
||||||
import StackSet
|
import StackSet hiding (filter)
|
||||||
import Operations (tile)
|
import Operations (tile)
|
||||||
|
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
Reference in New Issue
Block a user