XMonad.Util.Stack

xmonad-contrib-0.18.1: Community-maintained extensions for xmonad

Copyright | Quentin Moser <moserq@gmail.com>
License | BSD-style (see LICENSE)
Maintainer | orphaned
Stability | unstable
Portability | unportable
Safe Haskell | None
Language | Haskell2010

XMonad.Util.Stack

Contents

- Usage
- Conversions
- `Zipper` manipulation functions
  - Insertion, movement
  - Focus movement
  - Extraction
  - Sorting
  - Maps
  - Filters
  - Folds
- Other utility functions

Description

Utility functions for manipulating `Maybe Stack`s.

Synopsis

- type Zipper a = Maybe (Stack a)
- emptyZ :: Zipper a
- singletonZ :: a -> Zipper a
- fromIndex :: [a] -> Int -> Zipper a
- toIndex :: Zipper a -> ([a], Maybe Int)
- fromTags :: [Either a a] -> Zipper a
- toTags :: Zipper a -> [Either a a]
- zipperFocusedAtFirstOf :: Eq q => [q] -> [q] -> Zipper q
- insertUpZ :: a -> Zipper a -> Zipper a
- insertDownZ :: a -> Zipper a -> Zipper a
- swapUpZ :: Zipper a -> Zipper a
- swapDownZ :: Zipper a -> Zipper a
- swapMasterZ :: Zipper a -> Zipper a
- focusUpZ :: Zipper a -> Zipper a
- focusDownZ :: Zipper a -> Zipper a
- focusMasterZ :: Zipper a -> Zipper a
- findS :: (a -> Bool) -> Stack a -> Maybe (Stack a)
- findZ :: (a -> Bool) -> Zipper a -> Zipper a
- getFocusZ :: Zipper a -> Maybe a
- getIZ :: Int -> Zipper a -> Maybe a
- sortZ :: Ord a => Zipper a -> Zipper a
- sortByZ :: (a -> a -> Ordering) -> Zipper a -> Zipper a
- mapZ :: (Bool -> a -> b) -> Zipper a -> Zipper b
- mapZ_ :: (a -> b) -> Zipper a -> Zipper b
- mapZM :: Monad m => (Bool -> a -> m b) -> Zipper a -> m (Zipper b)
- mapZM_ :: Monad m => (a -> m b) -> Zipper a -> m (Zipper b)
- onFocusedZ :: (a -> a) -> Zipper a -> Zipper a
- onFocusedZM :: Monad m => (a -> m a) -> Zipper a -> m (Zipper a)
- onIndexZ :: Int -> (a -> a) -> Zipper a -> Zipper a
- onIndexZM :: Monad m => Int -> (a -> m a) -> Zipper a -> m (Zipper a)
- filterZ :: (Bool -> a -> Bool) -> Zipper a -> Zipper a
- filterZ_ :: (a -> Bool) -> Zipper a -> Zipper a
- deleteFocusedZ :: Zipper a -> Zipper a
- deleteIndexZ :: Int -> Zipper a -> Zipper a
- foldrZ :: (Bool -> a -> b -> b) -> b -> Zipper a -> b
- foldlZ :: (Bool -> b -> a -> b) -> b -> Zipper a -> b
- foldrZ_ :: (a -> b -> b) -> b -> Zipper a -> b
- foldlZ_ :: (b -> a -> b) -> b -> Zipper a -> b
- elemZ :: Eq a => a -> Zipper a -> Bool
- getI :: Int -> [a] -> Maybe a
- tagBy :: (a -> Bool) -> a -> Either a a
- fromE :: Either a a -> a
- mapE :: (Bool -> a -> b) -> Either a a -> Either b b
- mapE_ :: (a -> b) -> Either a a -> Either b b
- mapEM :: Monad m => (Bool -> a -> m b) -> Either a a -> m (Either b b)
- mapEM_ :: Monad m => (a -> m b) -> Either a a -> m (Either b b)
- reverseS :: Stack a -> Stack a
- reverseZ :: Zipper a -> Zipper a

# Usage

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

type Zipper a = Maybe (Stack a) #

emptyZ :: Zipper a #

singletonZ :: a -> Zipper a #

# Conversions

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

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) #

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

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

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] #

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

zipperFocusedAtFirstOf :: Eq q => [q] -> [q] -> Zipper q #

`differentiate zs xs` takes the first `z` from `z2 that also belongs to` xs`and turns` xs`into a stack with` z`being the current element. Acts as `differentiate` if` zs`and` xs@ don't intersect.

# `Zipper` manipulation functions

## Insertion, movement

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

Insert an element before the focused one, and focus it

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

Insert an element after the focused one, and focus it

swapUpZ :: Zipper a -> Zipper a #

Swap the focused element with the previous one

swapDownZ :: Zipper a -> Zipper a #

Swap the focused element with the next one

swapMasterZ :: Zipper a -> Zipper a #

Swap the focused element with the first one

## Focus movement

focusUpZ :: Zipper a -> Zipper a #

Move the focus to the previous element

focusDownZ :: Zipper a -> Zipper a #

Move the focus to the next element

focusMasterZ :: Zipper a -> Zipper a #

Move the focus to the first element

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

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

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

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

## Extraction

getFocusZ :: Zipper a -> Maybe a #

Get the focused element

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

Get the element at a given index

## Sorting

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

Sort a stack of elements supporting `Ord`

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

Sort a stack with an arbitrary sorting function

## Maps

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

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 #

`mapZ` without the `Bool` argument

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

Monadic version of `mapZ`

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

Monadic version of `mapZ_`

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

Apply a function to the focused element

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

Monadic version of `onFocusedZ`

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

Apply a function to the element at the given index

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

Monadic version of `onIndexZ`

## Filters

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

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 #

`filterZ` without the `Bool` argument

deleteFocusedZ :: Zipper a -> Zipper a #

Delete the focused element

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

Delete the ith element

## Folds

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

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 #

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 #

`foldrZ` without the `Bool` argument.

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

`foldlZ` without the `Bool` argument.

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

Find whether an element is present in a stack.

# Other utility functions

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

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

Safe version of `!!`

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

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

fromE :: Either a a -> a #

Get the `a` from an `Either a a`

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

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

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

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

Monadic version of `mapE`

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

reverseS :: Stack a -> Stack a #

Reverse a `Stack a`; O(1).

reverseZ :: Zipper a -> Zipper a #

Reverse a `Zipper a`; O(1).