xmonad-contrib-0.17.0: Community-maintained extensions extensions for xmonad
CopyrightQuentin Moser <moserq@gmail.com>
LicenseBSD-style (see LICENSE)
Maintainerorphaned
Stabilityunstable
Portabilityunportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

XMonad.Util.Stack

Description

Utility functions for manipulating Maybe Stacks.

Synopsis

Usage

This is a developer-oriented module, intended to be used for writing new extentions.

type Zipper a = Maybe (Stack a) Source #

Conversions

fromIndex :: [a] -> Int -> Zipper a Source #

Create a stack from a list, and the 0-based index of the focused element. If the index is out of bounds, focus will go to the first element.

toIndex :: Zipper a -> ([a], Maybe Int) Source #

Turn a stack into a list and the index of its focused element.

fromTags :: [Either a a] -> Zipper a Source #

Create a stack from a list of Either-tagged values. Focus will go to the first Right value, or if there is none, to the first Left one.

toTags :: Zipper a -> [Either a a] Source #

Turn a stack into an Either-tagged list. The focused element will be tagged with Right, the others with Left.

Zipper manipulation functions

Insertion, movement

insertUpZ :: a -> Zipper a -> Zipper a Source #

Insert an element before the focused one, and focus it

insertDownZ :: a -> Zipper a -> Zipper a Source #

Insert an element after the focused one, and focus it

swapUpZ :: Zipper a -> Zipper a Source #

Swap the focused element with the previous one

swapDownZ :: Zipper a -> Zipper a Source #

Swap the focused element with the next one

swapMasterZ :: Zipper a -> Zipper a Source #

Swap the focused element with the first one

Focus movement

focusUpZ :: Zipper a -> Zipper a Source #

Move the focus to the previous element

focusDownZ :: Zipper a -> Zipper a Source #

Move the focus to the next element

focusMasterZ :: Zipper a -> Zipper a Source #

Move the focus to the first element

findS :: (a -> Bool) -> Stack a -> Maybe (Stack a) Source #

Refocus a Stack a on an element satisfying the predicate, or fail to Nothing.

findZ :: (a -> Bool) -> Zipper a -> Zipper a Source #

Refocus a Zipper a on an element satisfying the predicate, or fail to Nothing.

Extraction

getFocusZ :: Zipper a -> Maybe a Source #

Get the focused element

getIZ :: Int -> Zipper a -> Maybe a Source #

Get the element at a given index

Sorting

sortZ :: Ord a => Zipper a -> Zipper a Source #

Sort a stack of elements supporting Ord

sortByZ :: (a -> a -> Ordering) -> Zipper a -> Zipper a Source #

Sort a stack with an arbitrary sorting function

Maps

mapZ :: (Bool -> a -> b) -> Zipper a -> Zipper b Source #

Map a function over a stack. The boolean argument indcates whether the current element is the focused one

mapZ_ :: (a -> b) -> Zipper a -> Zipper b Source #

mapZ without the Bool argument

mapZM :: Monad m => (Bool -> a -> m b) -> Zipper a -> m (Zipper b) Source #

Monadic version of mapZ

mapZM_ :: Monad m => (a -> m b) -> Zipper a -> m (Zipper b) Source #

Monadic version of mapZ_

onFocusedZ :: (a -> a) -> Zipper a -> Zipper a Source #

Apply a function to the focused element

onFocusedZM :: Monad m => (a -> m a) -> Zipper a -> m (Zipper a) Source #

Monadic version of onFocusedZ

onIndexZ :: Int -> (a -> a) -> Zipper a -> Zipper a Source #

Apply a function to the element at the given index

onIndexZM :: Monad m => Int -> (a -> m a) -> Zipper a -> m (Zipper a) Source #

Monadic version of onIndexZ

Filters

filterZ :: (Bool -> a -> Bool) -> Zipper a -> Zipper a Source #

Fiter a stack according to a predicate. The refocusing behavior mimics XMonad's usual one. The boolean argument indicates whether the current element is the focused one.

filterZ_ :: (a -> Bool) -> Zipper a -> Zipper a Source #

filterZ without the Bool argument

deleteFocusedZ :: Zipper a -> Zipper a Source #

Delete the focused element

deleteIndexZ :: Int -> Zipper a -> Zipper a Source #

Delete the ith element

Folds

foldrZ :: (Bool -> a -> b -> b) -> b -> Zipper a -> b Source #

Analogous to foldr. The Bool argument to the step functions indicates whether the current element is the focused one

foldlZ :: (Bool -> b -> a -> b) -> b -> Zipper a -> b Source #

Analogous to foldl. The Bool argument to the step functions indicates whether the current element is the focused one

foldrZ_ :: (a -> b -> b) -> b -> Zipper a -> b Source #

foldrZ without the Bool argument.

foldlZ_ :: (b -> a -> b) -> b -> Zipper a -> b Source #

foldlZ without the Bool argument.

elemZ :: Eq a => a -> Zipper a -> Bool Source #

Find whether an element is present in a stack.

Other utility functions

getI :: Int -> [a] -> Maybe a Source #

Deprecated: Use XMonad.Prelude.(!?) instead.

Safe version of !!

tagBy :: (a -> Bool) -> a -> Either a a Source #

Tag the element with Right if the property is true, Left otherwise

fromE :: Either a a -> a Source #

Get the a from an Either a a

mapE :: (Bool -> a -> b) -> Either a a -> Either b b Source #

Map a function across both Lefts and Rights. The Bool argument is True in a Right, False in a Left.

mapE_ :: (a -> b) -> Either a a -> Either b b Source #

mapEM :: Monad m => (Bool -> a -> m b) -> Either a a -> m (Either b b) Source #

Monadic version of mapE

mapEM_ :: Monad m => (a -> m b) -> Either a a -> m (Either b b) Source #

reverseS :: Stack a -> Stack a Source #

Reverse a Stack a; O(1).

reverseZ :: Zipper a -> Zipper a Source #

Reverse a Zipper a; O(1).