diff options
author | Spencer Janssen <sjanssen@cse.unl.edu> | 2007-06-11 18:51:54 +0200 |
---|---|---|
committer | Spencer Janssen <sjanssen@cse.unl.edu> | 2007-06-11 18:51:54 +0200 |
commit | 8e69e941d69ed129b63d4ba9303fe929c20e3879 (patch) | |
tree | 426a5e3189041e2b57f7c56b746f869852b93dd3 | |
parent | 40fc8649f6b4ec12b6bb83b6001ac34c23abb370 (diff) | |
download | metatile-8e69e941d69ed129b63d4ba9303fe929c20e3879.tar metatile-8e69e941d69ed129b63d4ba9303fe929c20e3879.zip |
Add StackSet.filter
darcs-hash:20070611165154-a5988-8c46751ffd4bd03249656e3b467b8e7569c48b09
-rw-r--r-- | StackSet.hs | 17 | ||||
-rw-r--r-- | tests/Properties.hs | 2 |
2 files changed, 16 insertions, 3 deletions
diff --git a/StackSet.hs b/StackSet.hs index 619d536..1b258fc 100644 --- a/StackSet.hs +++ b/StackSet.hs @@ -76,12 +76,13 @@ module StackSet ( StackSet(..), Workspace(..), Screen(..), Stack(..), RationalRect(..), 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 ) where +import Prelude hiding (filter) 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) -- | @@ -262,6 +263,18 @@ integrate Empty = [] 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. -- The order of the stack is determined by the master window -- it will be -- the head of the list. The implementation is given by the natural diff --git a/tests/Properties.hs b/tests/Properties.hs index 8a2d712..06e32a5 100644 --- a/tests/Properties.hs +++ b/tests/Properties.hs @@ -1,6 +1,6 @@ {-# OPTIONS -fglasgow-exts #-} -import StackSet +import StackSet hiding (filter) import Operations (tile) import Debug.Trace |