{-# LANGUAGE PatternGuards #-}
module XMonad.Util.Stack (
Zipper
, emptyZ
, singletonZ
, fromIndex
, toIndex
, fromTags
, toTags
, zipperFocusedAtFirstOf
, insertUpZ
, insertDownZ
, swapUpZ
, swapDownZ
, swapMasterZ
, focusUpZ
, focusDownZ
, focusMasterZ
, findS
, findZ
, getFocusZ
, getIZ
, sortZ
, sortByZ
, mapZ
, mapZ_
, mapZM
, mapZM_
, onFocusedZ
, onFocusedZM
, onIndexZ
, onIndexZM
, filterZ
, filterZ_
, deleteFocusedZ
, deleteIndexZ
, foldrZ
, foldlZ
, foldrZ_
, foldlZ_
, elemZ
, getI
, tagBy
, fromE
, mapE
, mapE_
, mapEM
, mapEM_
, reverseS
, reverseZ
) where
import qualified XMonad.StackSet as W
import XMonad.Prelude (guard, sortBy, (!?), (<|>))
type Zipper a = Maybe (W.Stack a)
emptyZ :: Zipper a
emptyZ :: forall a. Zipper a
emptyZ = Maybe (Stack a)
forall a. Maybe a
Nothing
singletonZ :: a -> Zipper a
singletonZ :: forall a. a -> Zipper a
singletonZ a
a = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
a [] []
fromIndex :: [a] -> Int -> Zipper a
fromIndex :: forall a. [a] -> Int -> Zipper a
fromIndex [a]
as Int
i = [Either a a] -> Zipper a
forall a. [Either a a] -> Zipper a
fromTags ([Either a a] -> Zipper a) -> [Either a a] -> Zipper a
forall a b. (a -> b) -> a -> b
$ ((a -> Either a a) -> a -> Either a a)
-> [a -> Either a a] -> [a] -> [Either a a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (a -> Either a a) -> a -> Either a a
forall a b. (a -> b) -> a -> b
($) (Int -> (a -> Either a a) -> [a -> Either a a]
forall a. Int -> a -> [a]
replicate Int
i a -> Either a a
forall a b. a -> Either a b
Left [a -> Either a a] -> [a -> Either a a] -> [a -> Either a a]
forall a. [a] -> [a] -> [a]
++ [a -> Either a a
forall a b. b -> Either a b
Right] [a -> Either a a] -> [a -> Either a a] -> [a -> Either a a]
forall a. [a] -> [a] -> [a]
++ (a -> Either a a) -> [a -> Either a a]
forall a. a -> [a]
repeat a -> Either a a
forall a b. a -> Either a b
Left) [a]
as
toIndex :: Zipper a -> ([a], Maybe Int)
toIndex :: forall a. Zipper a -> ([a], Maybe Int)
toIndex Maybe (Stack a)
Nothing = ([], Maybe Int
forall a. Maybe a
Nothing)
toIndex (Just Stack a
s) = (Stack a -> [a]
forall a. Stack a -> [a]
W.integrate Stack a
s, Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$ [a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([a] -> Int) -> [a] -> Int
forall a b. (a -> b) -> a -> b
$ Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s)
fromTags :: [Either a a] -> Zipper a
fromTags :: forall a. [Either a a] -> Zipper a
fromTags = ([a], Maybe a, [a]) -> Maybe (Stack a)
forall {a}. ([a], Maybe a, [a]) -> Maybe (Stack a)
finalize (([a], Maybe a, [a]) -> Maybe (Stack a))
-> ([Either a a] -> ([a], Maybe a, [a]))
-> [Either a a]
-> Maybe (Stack a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either a a -> ([a], Maybe a, [a]) -> ([a], Maybe a, [a]))
-> ([a], Maybe a, [a]) -> [Either a a] -> ([a], Maybe a, [a])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Either a a -> ([a], Maybe a, [a]) -> ([a], Maybe a, [a])
forall {a}.
Either a a -> ([a], Maybe a, [a]) -> ([a], Maybe a, [a])
step ([], Maybe a
forall a. Maybe a
Nothing, [])
where step :: Either a a -> ([a], Maybe a, [a]) -> ([a], Maybe a, [a])
step (Right a
a) ([a]
u, Just a
f, [a]
d) = ([], a -> Maybe a
forall a. a -> Maybe a
Just a
a, [a]
u[a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++a
fa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
d)
step (Right a
a) ([a]
u, Maybe a
Nothing, [a]
d) = ([a]
u, a -> Maybe a
forall a. a -> Maybe a
Just a
a, [a]
d)
step (Left a
a) ([a]
u, Just a
f, [a]
d) = (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
u, a -> Maybe a
forall a. a -> Maybe a
Just a
f, [a]
d)
step (Left a
a) ([a]
u, Maybe a
Nothing, [a]
d) = ([a]
u, Maybe a
forall a. Maybe a
Nothing, a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
d)
finalize :: ([a], Maybe a, [a]) -> Maybe (Stack a)
finalize ([a]
u, Just a
f, [a]
d) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
f ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
u) [a]
d
finalize ([a]
u, Maybe a
Nothing, a
a:[a]
d) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
a ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
u) [a]
d
finalize ([a]
_, Maybe a
Nothing, []) = Maybe (Stack a)
forall a. Maybe a
Nothing
toTags :: Zipper a -> [Either a a]
toTags :: forall a. Zipper a -> [Either a a]
toTags Maybe (Stack a)
Nothing = []
toTags (Just Stack a
s) = (a -> Either a a) -> [a] -> [Either a a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Either a a
forall a b. a -> Either a b
Left ([a] -> [a]
forall a. [a] -> [a]
reverse ([a] -> [a]) -> (Stack a -> [a]) -> Stack a -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack a -> [a]
forall a. Stack a -> [a]
W.up (Stack a -> [a]) -> Stack a -> [a]
forall a b. (a -> b) -> a -> b
$ Stack a
s) [Either a a] -> [Either a a] -> [Either a a]
forall a. [a] -> [a] -> [a]
++ [a -> Either a a
forall a b. b -> Either a b
Right (a -> Either a a) -> (Stack a -> a) -> Stack a -> Either a a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack a -> a
forall a. Stack a -> a
W.focus (Stack a -> Either a a) -> Stack a -> Either a a
forall a b. (a -> b) -> a -> b
$ Stack a
s]
[Either a a] -> [Either a a] -> [Either a a]
forall a. [a] -> [a] -> [a]
++ (a -> Either a a) -> [a] -> [Either a a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Either a a
forall a b. a -> Either a b
Left (Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s)
zipperFocusedAtFirstOf :: Eq q => [q] -> [q] -> Zipper q
zipperFocusedAtFirstOf :: forall q. Eq q => [q] -> [q] -> Zipper q
zipperFocusedAtFirstOf [] [q]
xs = [q] -> Maybe (Stack q)
forall a. [a] -> Maybe (Stack a)
W.differentiate [q]
xs
zipperFocusedAtFirstOf (q
z : [q]
zs) [q]
xs
| q
z q -> [q] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [q]
xs = Stack q -> Maybe (Stack q)
forall a. a -> Maybe a
Just (Stack q -> Maybe (Stack q)) -> Stack q -> Maybe (Stack q)
forall a b. (a -> b) -> a -> b
$
W.Stack { focus :: q
W.focus = q
z
, up :: [q]
W.up = [q] -> [q]
forall a. [a] -> [a]
reverse ([q] -> [q]) -> [q] -> [q]
forall a b. (a -> b) -> a -> b
$ (q -> Bool) -> [q] -> [q]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (q -> q -> Bool
forall a. Eq a => a -> a -> Bool
/= q
z) [q]
xs
, down :: [q]
W.down = Int -> [q] -> [q]
forall a. Int -> [a] -> [a]
drop Int
1 ([q] -> [q]) -> [q] -> [q]
forall a b. (a -> b) -> a -> b
$ (q -> Bool) -> [q] -> [q]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (q -> q -> Bool
forall a. Eq a => a -> a -> Bool
/= q
z) [q]
xs
}
| Bool
otherwise = [q] -> [q] -> Maybe (Stack q)
forall q. Eq q => [q] -> [q] -> Zipper q
zipperFocusedAtFirstOf [q]
zs [q]
xs
insertUpZ :: a -> Zipper a -> Zipper a
insertUpZ :: forall a. a -> Zipper a -> Zipper a
insertUpZ a
a Maybe (Stack a)
Nothing = [a] -> Maybe (Stack a)
forall a. [a] -> Maybe (Stack a)
W.differentiate [a
a]
insertUpZ a
a (Just Stack a
s) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.focus = a , W.down = W.focus s : W.down s }
insertDownZ :: a -> Zipper a -> Zipper a
insertDownZ :: forall a. a -> Zipper a -> Zipper a
insertDownZ a
a Maybe (Stack a)
Nothing = [a] -> Maybe (Stack a)
forall a. [a] -> Maybe (Stack a)
W.differentiate [a
a]
insertDownZ a
a (Just Stack a
s) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.focus = a, W.up = W.focus s : W.up s }
swapUpZ :: Zipper a -> Zipper a
swapUpZ :: forall a. Zipper a -> Zipper a
swapUpZ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
swapUpZ (Just Stack a
s) | a
u:[a]
up <- Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.up = up, W.down = u:W.down s}
swapUpZ (Just Stack a
s) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.up = reverse (W.down s), W.down = [] }
swapDownZ :: Zipper a -> Zipper a
swapDownZ :: forall a. Zipper a -> Zipper a
swapDownZ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
swapDownZ (Just Stack a
s) | a
d:[a]
down <- Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.down = down, W.up = d:W.up s }
swapDownZ (Just Stack a
s) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.up = [], W.down = reverse (W.up s) }
swapMasterZ :: Zipper a -> Zipper a
swapMasterZ :: forall a. Zipper a -> Zipper a
swapMasterZ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
swapMasterZ (Just (W.Stack a
f [a]
up [a]
down)) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
f [] ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
up [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a]
down)
focusUpZ :: Zipper a -> Zipper a
focusUpZ :: forall a. Zipper a -> Zipper a
focusUpZ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
focusUpZ (Just Stack a
s) | a
u:[a]
up <- Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
u [a]
up (Stack a -> a
forall a. Stack a -> a
W.focus Stack a
sa -> [a] -> [a]
forall a. a -> [a] -> [a]
:Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s)
focusUpZ (Just Stack a
s) | [a] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([a] -> Bool) -> [a] -> Bool
forall a b. (a -> b) -> a -> b
$ Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s
focusUpZ (Just (W.Stack a
f [a]
_ [a]
down)) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack ([a] -> a
forall a. HasCallStack => [a] -> a
last [a]
down) (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
1 ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
down) [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
f]) []
focusDownZ :: Zipper a -> Zipper a
focusDownZ :: forall a. Zipper a -> Zipper a
focusDownZ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
focusDownZ (Just Stack a
s) | a
d:[a]
down <- Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
d (Stack a -> a
forall a. Stack a -> a
W.focus Stack a
sa -> [a] -> [a]
forall a. a -> [a] -> [a]
:Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s) [a]
down
focusDownZ (Just Stack a
s) | [a] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([a] -> Bool) -> [a] -> Bool
forall a b. (a -> b) -> a -> b
$ Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s
focusDownZ (Just (W.Stack a
f [a]
up [a]
_)) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack ([a] -> a
forall a. HasCallStack => [a] -> a
last [a]
up) [] (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
1 ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
up) [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
f])
focusMasterZ :: Zipper a -> Zipper a
focusMasterZ :: forall a. Zipper a -> Zipper a
focusMasterZ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
focusMasterZ (Just (W.Stack a
f [a]
up [a]
down)) | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [a] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
up
= Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack ([a] -> a
forall a. HasCallStack => [a] -> a
last [a]
up) [] (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
1 ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
up) [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
f] [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a]
down)
focusMasterZ (Just Stack a
s) = Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s
findS :: (a -> Bool) -> W.Stack a -> Maybe (W.Stack a)
findS :: forall a. (a -> Bool) -> Stack a -> Maybe (Stack a)
findS a -> Bool
p Stack a
st = Stack a
st Stack a -> Maybe () -> Maybe (Stack a)
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> (Stack a -> Bool) -> Stack a -> Maybe ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
p (a -> Bool) -> (Stack a -> a) -> Stack a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack a -> a
forall a. Stack a -> a
W.focus) Stack a
st Maybe (Stack a) -> Maybe (Stack a) -> Maybe (Stack a)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Stack a -> Maybe (Stack a)
findUp Stack a
st Maybe (Stack a) -> Maybe (Stack a) -> Maybe (Stack a)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Stack a -> Maybe (Stack a)
findDown Stack a
st
where findDown :: Stack a -> Maybe (Stack a)
findDown = Maybe (Stack a) -> Maybe (Stack a)
forall a. Zipper a -> Zipper a
reverseZ (Maybe (Stack a) -> Maybe (Stack a))
-> (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack a -> Maybe (Stack a)
findUp (Stack a -> Maybe (Stack a))
-> (Stack a -> Stack a) -> Stack a -> Maybe (Stack a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack a -> Stack a
forall a. Stack a -> Stack a
reverseS
findUp :: Stack a -> Maybe (Stack a)
findUp Stack a
s | a
u:[a]
ups <- Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s = (if a -> Bool
p a
u then Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just else Stack a -> Maybe (Stack a)
findUp)
(Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
u [a]
ups (Stack a -> a
forall a. Stack a -> a
W.focus Stack a
s a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s)
| Bool
otherwise = Maybe (Stack a)
forall a. Maybe a
Nothing
findZ :: (a -> Bool) -> Zipper a -> Zipper a
findZ :: forall a. (a -> Bool) -> Zipper a -> Zipper a
findZ a -> Bool
_ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
findZ a -> Bool
p (Just Stack a
st) = (a -> Bool) -> Stack a -> Maybe (Stack a)
forall a. (a -> Bool) -> Stack a -> Maybe (Stack a)
findS a -> Bool
p Stack a
st
getFocusZ :: Zipper a -> Maybe a
getFocusZ :: forall a. Zipper a -> Maybe a
getFocusZ = (Stack a -> a) -> Maybe (Stack a) -> Maybe a
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Stack a -> a
forall a. Stack a -> a
W.focus
getIZ :: Int -> Zipper a -> Maybe a
getIZ :: forall a. Int -> Zipper a -> Maybe a
getIZ Int
i = Int -> [a] -> Maybe a
forall a. Int -> [a] -> Maybe a
getI Int
i ([a] -> Maybe a) -> (Zipper a -> [a]) -> Zipper a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Zipper a -> [a]
forall a. Maybe (Stack a) -> [a]
W.integrate'
sortZ :: Ord a => Zipper a -> Zipper a
sortZ :: forall a. Ord a => Zipper a -> Zipper a
sortZ = (a -> a -> Ordering) -> Zipper a -> Zipper a
forall a. (a -> a -> Ordering) -> Zipper a -> Zipper a
sortByZ a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare
sortByZ :: (a -> a -> Ordering) -> Zipper a -> Zipper a
sortByZ :: forall a. (a -> a -> Ordering) -> Zipper a -> Zipper a
sortByZ a -> a -> Ordering
f = [Either a a] -> Zipper a
forall a. [Either a a] -> Zipper a
fromTags ([Either a a] -> Zipper a)
-> (Zipper a -> [Either a a]) -> Zipper a -> Zipper a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either a a -> Either a a -> Ordering)
-> [Either a a] -> [Either a a]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy ((a -> a -> Ordering) -> Either a a -> Either a a -> Ordering
forall {t} {t} {t}. (t -> t -> t) -> Either t t -> Either t t -> t
adapt a -> a -> Ordering
f) ([Either a a] -> [Either a a])
-> (Zipper a -> [Either a a]) -> Zipper a -> [Either a a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Zipper a -> [Either a a]
forall a. Zipper a -> [Either a a]
toTags
where adapt :: (t -> t -> t) -> Either t t -> Either t t -> t
adapt t -> t -> t
g Either t t
e1 Either t t
e2 = t -> t -> t
g (Either t t -> t
forall a. Either a a -> a
fromE Either t t
e1) (Either t t -> t
forall a. Either a a -> a
fromE Either t t
e2)
mapZ :: (Bool -> a -> b) -> Zipper a -> Zipper b
mapZ :: forall a b. (Bool -> a -> b) -> Zipper a -> Zipper b
mapZ Bool -> a -> b
f = [Either b b] -> Zipper b
forall a. [Either a a] -> Zipper a
fromTags ([Either b b] -> Zipper b)
-> (Zipper a -> [Either b b]) -> Zipper a -> Zipper b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either a a -> Either b b) -> [Either a a] -> [Either b b]
forall a b. (a -> b) -> [a] -> [b]
map ((Bool -> a -> b) -> Either a a -> Either b b
forall a b. (Bool -> a -> b) -> Either a a -> Either b b
mapE Bool -> a -> b
f) ([Either a a] -> [Either b b])
-> (Zipper a -> [Either a a]) -> Zipper a -> [Either b b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Zipper a -> [Either a a]
forall a. Zipper a -> [Either a a]
toTags
mapZ_ :: (a -> b) -> Zipper a -> Zipper b
mapZ_ :: forall a b. (a -> b) -> Zipper a -> Zipper b
mapZ_ = (Bool -> a -> b) -> Zipper a -> Zipper b
forall a b. (Bool -> a -> b) -> Zipper a -> Zipper b
mapZ ((Bool -> a -> b) -> Zipper a -> Zipper b)
-> ((a -> b) -> Bool -> a -> b) -> (a -> b) -> Zipper a -> Zipper b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Bool -> a -> b
forall a b. a -> b -> a
const
mapZM :: Monad m => (Bool -> a -> m b) -> Zipper a -> m (Zipper b)
mapZM :: forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Zipper a -> m (Zipper b)
mapZM Bool -> a -> m b
f Zipper a
as = [Either b b] -> Zipper b
forall a. [Either a a] -> Zipper a
fromTags ([Either b b] -> Zipper b) -> m [Either b b] -> m (Zipper b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Either a a -> m (Either b b)) -> [Either a a] -> m [Either b b]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((Bool -> a -> m b) -> Either a a -> m (Either b b)
forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Either a a -> m (Either b b)
mapEM Bool -> a -> m b
f) ([Either a a] -> m [Either b b])
-> (Zipper a -> [Either a a]) -> Zipper a -> m [Either b b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Zipper a -> [Either a a]
forall a. Zipper a -> [Either a a]
toTags) Zipper a
as
mapZM_ :: Monad m => (a -> m b) -> Zipper a -> m (Zipper b)
mapZM_ :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Zipper a -> m (Zipper b)
mapZM_ = (Bool -> a -> m b) -> Zipper a -> m (Zipper b)
forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Zipper a -> m (Zipper b)
mapZM ((Bool -> a -> m b) -> Zipper a -> m (Zipper b))
-> ((a -> m b) -> Bool -> a -> m b)
-> (a -> m b)
-> Zipper a
-> m (Zipper b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m b) -> Bool -> a -> m b
forall a b. a -> b -> a
const
onFocusedZ :: (a -> a) -> Zipper a -> Zipper a
onFocusedZ :: forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ a -> a
f = (Bool -> a -> a) -> Zipper a -> Zipper a
forall a b. (Bool -> a -> b) -> Zipper a -> Zipper b
mapZ ((Bool -> a -> a) -> Zipper a -> Zipper a)
-> (Bool -> a -> a) -> Zipper a -> Zipper a
forall a b. (a -> b) -> a -> b
$ \Bool
b a
a -> if Bool
b then a -> a
f a
a else a
a
onFocusedZM :: Monad m => (a -> m a) -> Zipper a -> m (Zipper a)
onFocusedZM :: forall (m :: * -> *) a.
Monad m =>
(a -> m a) -> Zipper a -> m (Zipper a)
onFocusedZM a -> m a
f = (Bool -> a -> m a) -> Zipper a -> m (Zipper a)
forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Zipper a -> m (Zipper b)
mapZM ((Bool -> a -> m a) -> Zipper a -> m (Zipper a))
-> (Bool -> a -> m a) -> Zipper a -> m (Zipper a)
forall a b. (a -> b) -> a -> b
$ \Bool
b a
a -> if Bool
b then a -> m a
f a
a else a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
onIndexZ :: Int -> (a -> a) -> Zipper a -> Zipper a
onIndexZ :: forall a. Int -> (a -> a) -> Zipper a -> Zipper a
onIndexZ Int
i a -> a
_ Zipper a
as | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 = Zipper a
as
onIndexZ Int
i a -> a
f Zipper a
as = case Int -> [Either a a] -> ([Either a a], [Either a a])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
i ([Either a a] -> ([Either a a], [Either a a]))
-> [Either a a] -> ([Either a a], [Either a a])
forall a b. (a -> b) -> a -> b
$ Zipper a -> [Either a a]
forall a. Zipper a -> [Either a a]
toTags Zipper a
as of
([Either a a]
before, []) -> [Either a a] -> Zipper a
forall a. [Either a a] -> Zipper a
fromTags [Either a a]
before
([Either a a]
before, Either a a
a:[Either a a]
after) -> [Either a a] -> Zipper a
forall a. [Either a a] -> Zipper a
fromTags ([Either a a] -> Zipper a) -> [Either a a] -> Zipper a
forall a b. (a -> b) -> a -> b
$ [Either a a]
before [Either a a] -> [Either a a] -> [Either a a]
forall a. [a] -> [a] -> [a]
++ (Bool -> a -> a) -> Either a a -> Either a a
forall a b. (Bool -> a -> b) -> Either a a -> Either b b
mapE ((a -> a) -> Bool -> a -> a
forall a b. a -> b -> a
const a -> a
f) Either a a
a Either a a -> [Either a a] -> [Either a a]
forall a. a -> [a] -> [a]
: [Either a a]
after
onIndexZM :: Monad m => Int -> (a -> m a) -> Zipper a -> m (Zipper a)
onIndexZM :: forall (m :: * -> *) a.
Monad m =>
Int -> (a -> m a) -> Zipper a -> m (Zipper a)
onIndexZM Int
i a -> m a
f Zipper a
as = case Int -> [Either a a] -> ([Either a a], [Either a a])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
i ([Either a a] -> ([Either a a], [Either a a]))
-> [Either a a] -> ([Either a a], [Either a a])
forall a b. (a -> b) -> a -> b
$ Zipper a -> [Either a a]
forall a. Zipper a -> [Either a a]
toTags Zipper a
as of
([Either a a]
before, []) -> Zipper a -> m (Zipper a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Zipper a -> m (Zipper a)) -> Zipper a -> m (Zipper a)
forall a b. (a -> b) -> a -> b
$ [Either a a] -> Zipper a
forall a. [Either a a] -> Zipper a
fromTags [Either a a]
before
([Either a a]
before, Either a a
a:[Either a a]
after) -> do Either a a
a' <- (Bool -> a -> m a) -> Either a a -> m (Either a a)
forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Either a a -> m (Either b b)
mapEM ((a -> m a) -> Bool -> a -> m a
forall a b. a -> b -> a
const a -> m a
f) Either a a
a
Zipper a -> m (Zipper a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Zipper a -> m (Zipper a)) -> Zipper a -> m (Zipper a)
forall a b. (a -> b) -> a -> b
$ [Either a a] -> Zipper a
forall a. [Either a a] -> Zipper a
fromTags ([Either a a] -> Zipper a) -> [Either a a] -> Zipper a
forall a b. (a -> b) -> a -> b
$ [Either a a]
before [Either a a] -> [Either a a] -> [Either a a]
forall a. [a] -> [a] -> [a]
++ Either a a
a' Either a a -> [Either a a] -> [Either a a]
forall a. a -> [a] -> [a]
: [Either a a]
after
filterZ :: (Bool -> a -> Bool) -> Zipper a -> Zipper a
filterZ :: forall a. (Bool -> a -> Bool) -> Zipper a -> Zipper a
filterZ Bool -> a -> Bool
_ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
filterZ Bool -> a -> Bool
p (Just Stack a
s) = case ( Bool -> a -> Bool
p Bool
True (Stack a -> a
forall a. Stack a -> a
W.focus Stack a
s)
, (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> a -> Bool
p Bool
False) (Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s)
, (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> a -> Bool
p Bool
False) (Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s) ) of
(Bool
True, [a]
up', [a]
down') -> Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.up = up', W.down = down' }
(Bool
False, [], []) -> Maybe (Stack a)
forall a. Maybe a
Nothing
(Bool
False, a
f:[a]
up', []) -> Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.focus = f, W.up = up', W.down = [] }
(Bool
False, [a]
up', a
f:[a]
down') -> Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just Stack a
s { W.focus = f
, W.up = up'
, W.down = down' }
filterZ_ :: (a -> Bool) -> Zipper a -> Zipper a
filterZ_ :: forall a. (a -> Bool) -> Zipper a -> Zipper a
filterZ_ = (Bool -> a -> Bool) -> Zipper a -> Zipper a
forall a. (Bool -> a -> Bool) -> Zipper a -> Zipper a
filterZ ((Bool -> a -> Bool) -> Zipper a -> Zipper a)
-> ((a -> Bool) -> Bool -> a -> Bool)
-> (a -> Bool)
-> Zipper a
-> Zipper a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Bool) -> Bool -> a -> Bool
forall a b. a -> b -> a
const
deleteFocusedZ :: Zipper a -> Zipper a
deleteFocusedZ :: forall a. Zipper a -> Zipper a
deleteFocusedZ = (Bool -> a -> Bool) -> Zipper a -> Zipper a
forall a. (Bool -> a -> Bool) -> Zipper a -> Zipper a
filterZ (\Bool
b a
_ -> Bool -> Bool
not Bool
b)
deleteIndexZ :: Int -> Zipper a -> Zipper a
deleteIndexZ :: forall a. Int -> Zipper a -> Zipper a
deleteIndexZ Int
i Zipper a
z = let numbered :: Zipper (Int, a)
numbered = ([Either (Int, a) (Int, a)] -> Zipper (Int, a)
forall a. [Either a a] -> Zipper a
fromTags ([Either (Int, a) (Int, a)] -> Zipper (Int, a))
-> (Zipper a -> [Either (Int, a) (Int, a)])
-> Zipper a
-> Zipper (Int, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Either a a -> Either (Int, a) (Int, a))
-> [Int] -> [Either a a] -> [Either (Int, a) (Int, a)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> Either a a -> Either (Int, a) (Int, a)
forall {a} {b}. a -> Either b b -> Either (a, b) (a, b)
number [Int
0..] ([Either a a] -> [Either (Int, a) (Int, a)])
-> (Zipper a -> [Either a a])
-> Zipper a
-> [Either (Int, a) (Int, a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Zipper a -> [Either a a]
forall a. Zipper a -> [Either a a]
toTags) Zipper a
z
number :: a -> Either b b -> Either (a, b) (a, b)
number a
j = (Bool -> b -> (a, b)) -> Either b b -> Either (a, b) (a, b)
forall a b. (Bool -> a -> b) -> Either a a -> Either b b
mapE (\Bool
_ b
a -> (a
j,b
a))
in ((Int, a) -> a) -> Zipper (Int, a) -> Zipper a
forall a b. (a -> b) -> Zipper a -> Zipper b
mapZ_ (Int, a) -> a
forall a b. (a, b) -> b
snd (Zipper (Int, a) -> Zipper a) -> Zipper (Int, a) -> Zipper a
forall a b. (a -> b) -> a -> b
$ ((Int, a) -> Bool) -> Zipper (Int, a) -> Zipper (Int, a)
forall a. (a -> Bool) -> Zipper a -> Zipper a
filterZ_ ((Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/=Int
i) (Int -> Bool) -> ((Int, a) -> Int) -> (Int, a) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, a) -> Int
forall a b. (a, b) -> a
fst) Zipper (Int, a)
numbered
foldrZ :: (Bool -> a -> b -> b) -> b -> Zipper a -> b
foldrZ :: forall a b. (Bool -> a -> b -> b) -> b -> Zipper a -> b
foldrZ Bool -> a -> b -> b
_ b
b Maybe (Stack a)
Nothing = b
b
foldrZ Bool -> a -> b -> b
f b
b (Just Stack a
s) = let b1 :: b
b1 = (a -> b -> b) -> b -> [a] -> b
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Bool -> a -> b -> b
f Bool
False) b
b (Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s)
b2 :: b
b2 = Bool -> a -> b -> b
f Bool
True (Stack a -> a
forall a. Stack a -> a
W.focus Stack a
s) b
b1
b3 :: b
b3 = (b -> a -> b) -> b -> [a] -> b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl ((a -> b -> b) -> b -> a -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> b -> b) -> b -> a -> b) -> (a -> b -> b) -> b -> a -> b
forall a b. (a -> b) -> a -> b
$ Bool -> a -> b -> b
f Bool
False) b
b2 (Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s)
in b
b3
foldlZ :: (Bool -> b -> a -> b) -> b -> Zipper a -> b
foldlZ :: forall b a. (Bool -> b -> a -> b) -> b -> Zipper a -> b
foldlZ Bool -> b -> a -> b
_ b
b Maybe (Stack a)
Nothing = b
b
foldlZ Bool -> b -> a -> b
f b
b (Just Stack a
s) = let b1 :: b
b1 = (a -> b -> b) -> b -> [a] -> b
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((b -> a -> b) -> a -> b -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((b -> a -> b) -> a -> b -> b) -> (b -> a -> b) -> a -> b -> b
forall a b. (a -> b) -> a -> b
$ Bool -> b -> a -> b
f Bool
False) b
b (Stack a -> [a]
forall a. Stack a -> [a]
W.up Stack a
s)
b2 :: b
b2 = Bool -> b -> a -> b
f Bool
True b
b1 (Stack a -> a
forall a. Stack a -> a
W.focus Stack a
s)
b3 :: b
b3 = (b -> a -> b) -> b -> [a] -> b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (Bool -> b -> a -> b
f Bool
False) b
b2 (Stack a -> [a]
forall a. Stack a -> [a]
W.down Stack a
s)
in b
b3
foldrZ_ :: (a -> b -> b) -> b -> Zipper a -> b
foldrZ_ :: forall a b. (a -> b -> b) -> b -> Zipper a -> b
foldrZ_ = (Bool -> a -> b -> b) -> b -> Zipper a -> b
forall a b. (Bool -> a -> b -> b) -> b -> Zipper a -> b
foldrZ ((Bool -> a -> b -> b) -> b -> Zipper a -> b)
-> ((a -> b -> b) -> Bool -> a -> b -> b)
-> (a -> b -> b)
-> b
-> Zipper a
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b -> b) -> Bool -> a -> b -> b
forall a b. a -> b -> a
const
foldlZ_ :: (b -> a -> b) -> b -> Zipper a -> b
foldlZ_ :: forall b a. (b -> a -> b) -> b -> Zipper a -> b
foldlZ_ = (Bool -> b -> a -> b) -> b -> Zipper a -> b
forall b a. (Bool -> b -> a -> b) -> b -> Zipper a -> b
foldlZ ((Bool -> b -> a -> b) -> b -> Zipper a -> b)
-> ((b -> a -> b) -> Bool -> b -> a -> b)
-> (b -> a -> b)
-> b
-> Zipper a
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> a -> b) -> Bool -> b -> a -> b
forall a b. a -> b -> a
const
elemZ :: Eq a => a -> Zipper a -> Bool
elemZ :: forall a. Eq a => a -> Zipper a -> Bool
elemZ a
a = (Bool -> a -> Bool) -> Bool -> Zipper a -> Bool
forall b a. (b -> a -> b) -> b -> Zipper a -> b
foldlZ_ Bool -> a -> Bool
step Bool
False
where step :: Bool -> a -> Bool
step Bool
True a
_ = Bool
True
step Bool
False a
a' = a
a' a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a
getI :: Int -> [a] -> Maybe a
getI :: forall a. Int -> [a] -> Maybe a
getI Int
i [a]
xs = [a]
xs [a] -> Int -> Maybe a
forall a. [a] -> Int -> Maybe a
!? Int
i
{-# DEPRECATED getI "Use XMonad.Prelude.(!?) instead." #-}
mapE :: (Bool -> a -> b) -> Either a a -> Either b b
mapE :: forall a b. (Bool -> a -> b) -> Either a a -> Either b b
mapE Bool -> a -> b
f (Left a
a) = b -> Either b b
forall a b. a -> Either a b
Left (b -> Either b b) -> b -> Either b b
forall a b. (a -> b) -> a -> b
$ Bool -> a -> b
f Bool
False a
a
mapE Bool -> a -> b
f (Right a
a) = b -> Either b b
forall a b. b -> Either a b
Right (b -> Either b b) -> b -> Either b b
forall a b. (a -> b) -> a -> b
$ Bool -> a -> b
f Bool
True a
a
mapE_ :: (a -> b) -> Either a a -> Either b b
mapE_ :: forall a b. (a -> b) -> Either a a -> Either b b
mapE_ = (Bool -> a -> b) -> Either a a -> Either b b
forall a b. (Bool -> a -> b) -> Either a a -> Either b b
mapE ((Bool -> a -> b) -> Either a a -> Either b b)
-> ((a -> b) -> Bool -> a -> b)
-> (a -> b)
-> Either a a
-> Either b b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Bool -> a -> b
forall a b. a -> b -> a
const
mapEM :: Monad m => (Bool -> a -> m b) -> Either a a -> m (Either b b)
mapEM :: forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Either a a -> m (Either b b)
mapEM Bool -> a -> m b
f (Left a
a) = b -> Either b b
forall a b. a -> Either a b
Left (b -> Either b b) -> m b -> m (Either b b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> a -> m b
f Bool
False a
a
mapEM Bool -> a -> m b
f (Right a
a) = b -> Either b b
forall a b. b -> Either a b
Right (b -> Either b b) -> m b -> m (Either b b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> a -> m b
f Bool
True a
a
mapEM_ :: Monad m => (a -> m b) -> Either a a -> m (Either b b)
mapEM_ :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Either a a -> m (Either b b)
mapEM_ = (Bool -> a -> m b) -> Either a a -> m (Either b b)
forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Either a a -> m (Either b b)
mapEM ((Bool -> a -> m b) -> Either a a -> m (Either b b))
-> ((a -> m b) -> Bool -> a -> m b)
-> (a -> m b)
-> Either a a
-> m (Either b b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m b) -> Bool -> a -> m b
forall a b. a -> b -> a
const
fromE :: Either a a -> a
fromE :: forall a. Either a a -> a
fromE (Right a
a) = a
a
fromE (Left a
a) = a
a
tagBy :: (a -> Bool) -> a -> Either a a
tagBy :: forall a. (a -> Bool) -> a -> Either a a
tagBy a -> Bool
p a
a = if a -> Bool
p a
a then a -> Either a a
forall a b. b -> Either a b
Right a
a else a -> Either a a
forall a b. a -> Either a b
Left a
a
reverseS :: W.Stack a -> W.Stack a
reverseS :: forall a. Stack a -> Stack a
reverseS (W.Stack a
foc [a]
ups [a]
downs) = a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
foc [a]
downs [a]
ups
reverseZ :: Zipper a -> Zipper a
reverseZ :: forall a. Zipper a -> Zipper a
reverseZ = (Stack a -> Stack a
forall a. Stack a -> Stack a
reverseS (Stack a -> Stack a) -> Maybe (Stack a) -> Maybe (Stack a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>)