A.CycleWindows replace partial rotUp and rotDown with safer versions

Rather than throw exceptions, handle null and singleton lists, i.e.
f [] gives [] and f [x] gives [x].
This commit is contained in:
Wirt Wolff
2010-01-23 23:19:12 +00:00
parent a9f2b82337
commit 57c00ea498

View File

@@ -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