From fe0867cad9031b954185296fc2ff0825efc95bda Mon Sep 17 00:00:00 2001 From: Wirt Wolff Date: Sun, 24 Jan 2010 00:19:12 +0100 Subject: A.CycleWindows replace partial rotUp and rotDown with safer versions Ignore-this: 6b4e40c15b66fc53096910e85e736c23 Rather than throw exceptions, handle null and singleton lists, i.e. f [] gives [] and f [x] gives [x]. darcs-hash:20100123231912-18562-6986c6acb711331ab135e62e1a41fbe8aabf5f13.gz --- XMonad/Actions/CycleWindows.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'XMonad') diff --git a/XMonad/Actions/CycleWindows.hs b/XMonad/Actions/CycleWindows.hs index a1d2fee..97e667b 100644 --- a/XMonad/Actions/CycleWindows.hs +++ b/XMonad/Actions/CycleWindows.hs @@ -226,8 +226,10 @@ rotUnfocused' f (W.Stack t ls rs) = W.Stack t (reverse revls') rs' -- otherwis (revls',rs') = splitAt (length ls) (f $ master:revls ++ rs) -- $generic --- Generic list rotations +-- Generic list rotations such that @rotUp [1..4]@ is equivalent to +-- @[2,3,4,1]@ and @rotDown [1..4]@ to @[4,1,2,3]@. They both are +-- @id@ for null or singleton lists. rotUp :: [a] -> [a] -rotUp l = tail l ++ [head l] +rotUp l = drop 1 l ++ take 1 l rotDown :: [a] -> [a] -rotDown l = last l : init l +rotDown = reverse . rotUp . reverse -- cgit v1.2.3