summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Janssen <sjanssen@cse.unl.edu>2007-05-08 16:39:51 +0200
committerSpencer Janssen <sjanssen@cse.unl.edu>2007-05-08 16:39:51 +0200
commitbc0db7c00b01ee9f16bdce040ff1298b25a3a1b6 (patch)
tree56b46061aa5d1fb7b6318433eab2f03e38bef23b
parent1f57620df2ff18881007b3bc56fb8ffbe5efbccf (diff)
downloadmetatile-bc0db7c00b01ee9f16bdce040ff1298b25a3a1b6.tar
metatile-bc0db7c00b01ee9f16bdce040ff1298b25a3a1b6.zip
StackSet.view: ignore invalid indices
darcs-hash:20070508143951-a5988-5b1aea6415436bc5cee632a60efc42300cfbf1e9
-rw-r--r--StackSet.hs6
1 files changed, 3 insertions, 3 deletions
diff --git a/StackSet.hs b/StackSet.hs
index 7883daa..74d63eb 100644
--- a/StackSet.hs
+++ b/StackSet.hs
@@ -104,13 +104,13 @@ index k w = uncurry (++) $ fromJust $ M.lookup k (stacks w)
-- | view. Set the stack specified by the argument as being visible and the
-- current StackSet. If the stack wasn't previously visible, it will become
--- visible on the current screen. If the index is out of range an exception is
--- thrown.
+-- visible on the current screen. If the index is out of range 'view' returns
+-- the initial 'StackSet' unchanged.
view :: (Integral i, Integral j) => i -> StackSet i j a -> StackSet i j a
view n w | M.member n (stacks w)
= if M.member n (ws2screen w) then w { current = n }
else tweak (fromJust $ screen (current w) w)
- | otherwise = error $ "view: index out of bounds: " ++ show n
+ | otherwise = w
where
tweak sc = w { screen2ws = M.insert sc n (screen2ws w)
, ws2screen = M.insert n sc (M.filter (/=sc) (ws2screen w))