fromList/toList have # of screens + another QC property

This commit is contained in:
Jason Creighton
2007-04-11 04:42:15 +00:00
parent ac913104a5
commit c6dcc9d869
2 changed files with 19 additions and 10 deletions

View File

@@ -80,20 +80,21 @@ size = M.size . stacks
-- | fromList. Build a new StackSet from a list of list of elements
-- If there are duplicates in the list, the last occurence wins.
-- FIXME: This always makes a StackSet with 1 screen.
fromList :: Ord a => (Int,[[a]]) -> StackSet a
fromList (_,[]) = error "Cannot build a StackSet from an empty list"
fromList :: Ord a => (Int,Int,[[a]]) -> StackSet a
fromList (_,_,[]) = error "Cannot build a StackSet from an empty list"
fromList (n,xs) | n < 0 || n >= length xs
fromList (n,m,xs) | n < 0 || n >= length xs
= error $ "Cursor index is out of range: " ++ show (n, length xs)
| m < 1 || m > length xs
= error $ "Can't have more screens than workspaces: " ++ show (m, length xs)
fromList (o,xs) = view o $ foldr (\(i,ys) s ->
foldr (\a t -> insert a i t) s ys)
(empty (length xs) 1) (zip [0..] xs)
fromList (o,m,xs) = view o $ foldr (\(i,ys) s ->
foldr (\a t -> insert a i t) s ys)
(empty (length xs) m) (zip [0..] xs)
-- | toList. Flatten a stackset to a list of lists
toList :: StackSet a -> (Int,[[a]])
toList x = (current x, map snd $ M.toList (stacks x))
toList :: StackSet a -> (Int,Int,[[a]])
toList x = (current x, M.size $ screen2ws x, map snd $ M.toList (stacks x))
-- | Push. Insert an element onto the top of the current stack.
-- If the element is already in the current stack, it is moved to the top.