summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Janssen <sjanssen@cse.unl.edu>2007-06-04 20:31:43 +0200
committerSpencer Janssen <sjanssen@cse.unl.edu>2007-06-04 20:31:43 +0200
commit9dbe49802ab820439e4072b8c060775523836e3e (patch)
tree6fac32492dc205aab5a9b1a384b69f91a949630e
parent87353a16e15506c9ec54cbbe7d5010d09f6778c3 (diff)
downloadmetatile-9dbe49802ab820439e4072b8c060775523836e3e.tar
metatile-9dbe49802ab820439e4072b8c060775523836e3e.zip
focusUp/Down are the same, in reversed order
darcs-hash:20070604183143-a5988-9b9325a10eee13bb6bd96d20ca3b15c12c368883
-rw-r--r--StackSet.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/StackSet.hs b/StackSet.hs
index 8f8c4e3..d1fe054 100644
--- a/StackSet.hs
+++ b/StackSet.hs
@@ -271,13 +271,12 @@ index = with [] integrate
-- the current stack.
--
focusUp, focusDown, swapUp, swapDown :: StackSet i a s -> StackSet i a s
-focusUp = modify Empty $ \c -> case c of
- Node t (l:ls) rs -> Node l ls (t:rs)
- Node t [] rs -> Node x xs [] where (x:xs) = reverse (t:rs)
+focusUp = modify Empty focusUp'
-focusDown = modify Empty $ \c -> case c of
- Node t ls (r:rs) -> Node r (t:ls) rs
- Node t ls [] -> Node x [] xs where (x:xs) = reverse (t:ls)
+focusUp' (Node t (l:ls) rs) = Node l ls (t:rs)
+focusUp' (Node t [] rs) = Node x xs [] where (x:xs) = reverse (t:rs)
+
+focusDown = modify Empty (reverseStack . focusUp' . reverseStack)
swapUp = modify Empty $ \c -> case c of
Node _ [] [] -> c
@@ -289,6 +288,10 @@ swapDown = modify Empty $ \c -> case c of
Node t ls (r:rs) -> Node t (r:ls) rs
Node t ls [] -> Node t [] (reverse ls)
+-- reverse a stack: up becomes down and down becomes up.
+reverseStack (Node t ls rs) = Node t rs ls
+reverseStack x = x
+
--
-- | /O(1) on current window, O(n) in general/. Focus the window 'w',
-- and set its workspace as current.