aboutsummaryrefslogtreecommitdiffstats
path: root/StackSet.hs
diff options
context:
space:
mode:
authorDon Stewart <dons@cse.unsw.edu.au>2007-06-26 05:57:41 +0200
committerDon Stewart <dons@cse.unsw.edu.au>2007-06-26 05:57:41 +0200
commit05d2dfcb0eea5b8149487dfad0e91e89d3151ad3 (patch)
tree60cba7f2c4858089b09b0d8cce925762bda3c643 /StackSet.hs
parent983c66301f8bf0270ab4462c1272c8e8077c3b61 (diff)
downloadxmonad-05d2dfcb0eea5b8149487dfad0e91e89d3151ad3.tar.gz
xmonad-05d2dfcb0eea5b8149487dfad0e91e89d3151ad3.tar.xz
xmonad-05d2dfcb0eea5b8149487dfad0e91e89d3151ad3.zip
fix empty case in 'filter', and note differences in semantics wrt. focus to 'delete'
darcs-hash:20070626035741-9c5c1-17c1fa07eed1fe3b9765530a8ab7966c195920e0.gz
Diffstat (limited to 'StackSet.hs')
-rw-r--r--StackSet.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/StackSet.hs b/StackSet.hs
index e57e80e..f4f482d 100644
--- a/StackSet.hs
+++ b/StackSet.hs
@@ -302,11 +302,16 @@ differentiate (x:xs) = Just $ Stack x [] xs
-- /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).
+--
+-- Note, this isn't the same as the 'remove' semantics, as focus
+-- won't move 'left' on the end of list.
+--
filter :: (a -> Bool) -> Stack a -> StackOrNot a
-filter p (Stack f ls rs) = Just $ case L.filter p (f:rs) of
- (f':rs') -> Stack f' (L.filter p ls) rs'
- _ -> Stack f' [] rs'
- where (f':rs') = reverse (L.filter p ls)
+filter p (Stack f ls rs) = case L.filter p (f:rs) of
+ f':rs' -> Just $ Stack f' (L.filter p ls) rs' -- maybe move focus down
+ [] -> case L.filter p (reverse ls) of -- filter back up
+ f':rs' -> Just $ Stack f' [] rs' -- else up
+ [] -> Nothing
-- |
-- /O(s)/. Extract the stack on the current workspace, as a list.