{-# LANGUAGE KindSignatures #-}
module Brick.Widgets.List.Skip (
Dir(..)
, Amount(..)
, Move(..)
, listSkip
, listSearchFromCurrent
, listShow
, Searchable(..)
) where
import Prelude hiding (take, drop)
import Lens.Micro
import qualified Data.Vector as V
import Data.Vector hiding (take, drop, modify)
import qualified Data.Sequence as S
import Data.Sequence hiding (take, drop)
import qualified Brick.Widgets.List as L
import Brick.Types hiding (Direction(..))
import Brick.Main
data IncludeCurrent = IncludeCurrent | ExcludeCurrent deriving (Int -> IncludeCurrent -> ShowS
[IncludeCurrent] -> ShowS
IncludeCurrent -> String
(Int -> IncludeCurrent -> ShowS)
-> (IncludeCurrent -> String)
-> ([IncludeCurrent] -> ShowS)
-> Show IncludeCurrent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IncludeCurrent -> ShowS
showsPrec :: Int -> IncludeCurrent -> ShowS
$cshow :: IncludeCurrent -> String
show :: IncludeCurrent -> String
$cshowList :: [IncludeCurrent] -> ShowS
showList :: [IncludeCurrent] -> ShowS
Show, IncludeCurrent -> IncludeCurrent -> Bool
(IncludeCurrent -> IncludeCurrent -> Bool)
-> (IncludeCurrent -> IncludeCurrent -> Bool) -> Eq IncludeCurrent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IncludeCurrent -> IncludeCurrent -> Bool
== :: IncludeCurrent -> IncludeCurrent -> Bool
$c/= :: IncludeCurrent -> IncludeCurrent -> Bool
/= :: IncludeCurrent -> IncludeCurrent -> Bool
Eq)
data Dir =
Bwd |
Fwd
deriving (Int -> Dir -> ShowS
[Dir] -> ShowS
Dir -> String
(Int -> Dir -> ShowS)
-> (Dir -> String) -> ([Dir] -> ShowS) -> Show Dir
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Dir -> ShowS
showsPrec :: Int -> Dir -> ShowS
$cshow :: Dir -> String
show :: Dir -> String
$cshowList :: [Dir] -> ShowS
showList :: [Dir] -> ShowS
Show, Dir -> Dir -> Bool
(Dir -> Dir -> Bool) -> (Dir -> Dir -> Bool) -> Eq Dir
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Dir -> Dir -> Bool
== :: Dir -> Dir -> Bool
$c/= :: Dir -> Dir -> Bool
/= :: Dir -> Dir -> Bool
Eq)
data Amount =
One |
Most |
Page |
HalfPage
deriving (Int -> Amount -> ShowS
[Amount] -> ShowS
Amount -> String
(Int -> Amount -> ShowS)
-> (Amount -> String) -> ([Amount] -> ShowS) -> Show Amount
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Amount -> ShowS
showsPrec :: Int -> Amount -> ShowS
$cshow :: Amount -> String
show :: Amount -> String
$cshowList :: [Amount] -> ShowS
showList :: [Amount] -> ShowS
Show, Amount -> Amount -> Bool
(Amount -> Amount -> Bool)
-> (Amount -> Amount -> Bool) -> Eq Amount
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Amount -> Amount -> Bool
== :: Amount -> Amount -> Bool
$c/= :: Amount -> Amount -> Bool
/= :: Amount -> Amount -> Bool
Eq)
data Move =
Move Amount Dir |
NoMove
deriving (Int -> Move -> ShowS
[Move] -> ShowS
Move -> String
(Int -> Move -> ShowS)
-> (Move -> String) -> ([Move] -> ShowS) -> Show Move
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Move -> ShowS
showsPrec :: Int -> Move -> ShowS
$cshow :: Move -> String
show :: Move -> String
$cshowList :: [Move] -> ShowS
showList :: [Move] -> ShowS
Show, Move -> Move -> Bool
(Move -> Move -> Bool) -> (Move -> Move -> Bool) -> Eq Move
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Move -> Move -> Bool
== :: Move -> Move -> Bool
$c/= :: Move -> Move -> Bool
/= :: Move -> Move -> Bool
Eq)
listSkip :: (Foldable t, L.Splittable t, Searchable t, Ord n)
=> (e -> Bool)
-> Move
-> EventM n (L.GenericList n t e) ()
listSkip :: forall (t :: * -> *) n e.
(Foldable t, Splittable t, Searchable t, Ord n) =>
(e -> Bool) -> Move -> EventM n (GenericList n t e) ()
listSkip e -> Bool
t Move
m = case Move
m of
Move Amount
a Dir
Bwd -> do
case Amount
a of
Amount
One -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ())
-> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ (e -> Bool) -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipBackward e -> Bool
t
Amount
Most -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ())
-> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ (e -> Bool) -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) e n.
(Searchable t, Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipToBeginning e -> Bool
t
Amount
Page -> (e -> Bool) -> Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n pages e.
(Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) =>
(e -> Bool) -> pages -> EventM n (GenericList n t e) ()
listSkipByPages e -> Bool
t (-Double
1.0)
Amount
HalfPage -> (e -> Bool) -> Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n pages e.
(Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) =>
(e -> Bool) -> pages -> EventM n (GenericList n t e) ()
listSkipByPages e -> Bool
t (-Double
0.5)
(e -> Bool) -> Dir -> EventM n (GenericList n t e) ()
forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> Dir -> EventM n (GenericList n t e) ()
listShow e -> Bool
t Dir
Bwd
Move Amount
a Dir
Fwd -> do
case Amount
a of
Amount
One -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ())
-> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ (e -> Bool) -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipForward e -> Bool
t
Amount
Most -> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ())
-> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ (e -> Bool) -> GenericList n t e -> GenericList n t e
forall (t :: * -> *) e n.
(Searchable t, Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipToEnd e -> Bool
t
Amount
Page -> (e -> Bool) -> Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n pages e.
(Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) =>
(e -> Bool) -> pages -> EventM n (GenericList n t e) ()
listSkipByPages e -> Bool
t Double
1.0
Amount
HalfPage -> (e -> Bool) -> Double -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n pages e.
(Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) =>
(e -> Bool) -> pages -> EventM n (GenericList n t e) ()
listSkipByPages e -> Bool
t Double
0.5
(e -> Bool) -> Dir -> EventM n (GenericList n t e) ()
forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> Dir -> EventM n (GenericList n t e) ()
listShow e -> Bool
t Dir
Fwd
Move
NoMove -> () -> EventM n (GenericList n t e) ()
forall a. a -> EventM n (GenericList n t e) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
listSearchFromCurrent :: Searchable t
=> (e -> Bool)
-> Dir
-> EventM n (L.GenericList n t e) ()
listSearchFromCurrent :: forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> Dir -> EventM n (GenericList n t e) ()
listSearchFromCurrent e -> Bool
t Dir
d = let
searchList :: IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
searchList = case Dir
d of
Dir
Bwd -> IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListBackward
Dir
Fwd -> IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListForward
in (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ())
-> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ \GenericList n t e
l -> case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall {e} {n}.
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
searchList IncludeCurrent
IncludeCurrent e -> Bool
t GenericList n t e
l of
Maybe Int
Nothing -> GenericList n t e
l
Just Int
ix -> GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Int
ix
listShow :: Searchable t
=> (e -> Bool)
-> Dir
-> EventM n (L.GenericList n t e) ()
listShow :: forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> Dir -> EventM n (GenericList n t e) ()
listShow e -> Bool
t Dir
d = do
GenericList n t e
l <- EventM n (GenericList n t e) (GenericList n t e)
forall s (m :: * -> *). MonadState s m => m s
get
let (IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipList, ViewportScroll n -> EventM n s ()
vScroll) = case Dir
d of
Dir
Bwd -> (IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListBackward, \ViewportScroll n
s -> ViewportScroll n -> forall s. EventM n s ()
forall n. ViewportScroll n -> forall s. EventM n s ()
vScrollToBeginning ViewportScroll n
s)
Dir
Fwd -> (IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListForward, \ViewportScroll n
s -> ViewportScroll n -> forall s. EventM n s ()
forall n. ViewportScroll n -> forall s. EventM n s ()
vScrollToEnd ViewportScroll n
s)
case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall {e} {n}.
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipList IncludeCurrent
ExcludeCurrent e -> Bool
t GenericList n t e
l of
Maybe Int
Nothing -> ViewportScroll n -> EventM n (GenericList n t e) ()
forall {n} {s}. ViewportScroll n -> EventM n s ()
vScroll (ViewportScroll n -> EventM n (GenericList n t e) ())
-> ViewportScroll n -> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ n -> ViewportScroll n
forall n. n -> ViewportScroll n
viewportScroll (n -> ViewportScroll n) -> n -> ViewportScroll n
forall a b. (a -> b) -> a -> b
$ GenericList n t e
l GenericList n t e -> Getting n (GenericList n t e) n -> n
forall s a. s -> Getting a s a -> a
^. Getting n (GenericList n t e) n
forall n1 (t :: * -> *) e n2 (f :: * -> *).
Functor f =>
(n1 -> f n2) -> GenericList n1 t e -> f (GenericList n2 t e)
L.listNameL
Just Int
_ -> () -> EventM n (GenericList n t e) ()
forall a. a -> EventM n (GenericList n t e) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
skipListForward :: Searchable t
=> IncludeCurrent
-> (e -> Bool)
-> L.GenericList n t e
-> Maybe Int
skipListForward :: forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListForward IncludeCurrent
incCur e -> Bool
test GenericList n t e
l = let
skipForward :: a -> t e -> Maybe a
skipForward a
idx t e
es = case t e -> Maybe (e, t e)
forall a. t a -> Maybe (a, t a)
forall (t :: * -> *) a. Searchable t => t a -> Maybe (a, t a)
viewHead t e
es of
Maybe (e, t e)
Nothing -> Maybe a
forall a. Maybe a
Nothing
Just (e
e, t e
es') -> if e -> Bool
test e
e
then a -> t e -> Maybe a
skipForward (a
idxa -> a -> a
forall a. Num a => a -> a -> a
+a
1) t e
es'
else a -> Maybe a
forall a. a -> Maybe a
Just a
idx
start :: Int
start = case GenericList n t e
l GenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL of
Maybe Int
Nothing -> Int
0
Just Int
i -> Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ case IncludeCurrent
incCur of
IncludeCurrent
IncludeCurrent -> Int
0
IncludeCurrent
ExcludeCurrent -> Int
1
es :: t e
es = Int -> t e -> t e
forall a. Int -> t a -> t a
forall (t :: * -> *) a. Searchable t => Int -> t a -> t a
drop Int
start (t e -> t e) -> t e -> t e
forall a b. (a -> b) -> a -> b
$ GenericList n t e
l GenericList n t e -> Getting (t e) (GenericList n t e) (t e) -> t e
forall s a. s -> Getting a s a -> a
^. Getting (t e) (GenericList n t e) (t e)
forall n (t1 :: * -> *) e1 (t2 :: * -> *) e2 (f :: * -> *).
Functor f =>
(t1 e1 -> f (t2 e2))
-> GenericList n t1 e1 -> f (GenericList n t2 e2)
L.listElementsL
in Int -> t e -> Maybe Int
forall {t :: * -> *} {a}.
(Searchable t, Num a) =>
a -> t e -> Maybe a
skipForward Int
start t e
es
skipListBackward :: Searchable t
=> IncludeCurrent
-> (e -> Bool)
-> L.GenericList n t e
-> Maybe Int
skipListBackward :: forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListBackward IncludeCurrent
incCur e -> Bool
test GenericList n t e
l = let
skipBackward :: a -> t e -> Maybe a
skipBackward a
idx t e
es = case t e -> Maybe (t e, e)
forall a. t a -> Maybe (t a, a)
forall (t :: * -> *) a. Searchable t => t a -> Maybe (t a, a)
viewLast t e
es of
Maybe (t e, e)
Nothing -> Maybe a
forall a. Maybe a
Nothing
Just (t e
es', e
e) -> if e -> Bool
test e
e
then a -> t e -> Maybe a
skipBackward (a
idxa -> a -> a
forall a. Num a => a -> a -> a
-a
1) t e
es'
else a -> Maybe a
forall a. a -> Maybe a
Just a
idx
start :: Int
start = case GenericList n t e
l GenericList n t e
-> Getting (Maybe Int) (GenericList n t e) (Maybe Int) -> Maybe Int
forall s a. s -> Getting a s a -> a
^. Getting (Maybe Int) (GenericList n t e) (Maybe Int)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL of
Maybe Int
Nothing -> Int
0
Just Int
i -> Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ case IncludeCurrent
incCur of
IncludeCurrent
IncludeCurrent -> Int
1
IncludeCurrent
ExcludeCurrent -> Int
0
es :: t e
es = Int -> t e -> t e
forall a. Int -> t a -> t a
forall (t :: * -> *) a. Searchable t => Int -> t a -> t a
take Int
start (t e -> t e) -> t e -> t e
forall a b. (a -> b) -> a -> b
$ GenericList n t e
l GenericList n t e -> Getting (t e) (GenericList n t e) (t e) -> t e
forall s a. s -> Getting a s a -> a
^. Getting (t e) (GenericList n t e) (t e)
forall n (t1 :: * -> *) e1 (t2 :: * -> *) e2 (f :: * -> *).
Functor f =>
(t1 e1 -> f (t2 e2))
-> GenericList n t1 e1 -> f (GenericList n t2 e2)
L.listElementsL
in Int -> t e -> Maybe Int
forall {t :: * -> *} {a}.
(Searchable t, Num a) =>
a -> t e -> Maybe a
skipBackward (Int
startInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) t e
es
listSkipBackward :: Searchable t
=> (e -> Bool)
-> L.GenericList n t e
-> L.GenericList n t e
listSkipBackward :: forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipBackward e -> Bool
test GenericList n t e
l = case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListBackward IncludeCurrent
ExcludeCurrent e -> Bool
test GenericList n t e
l of
Maybe Int
Nothing -> GenericList n t e
l
Just Int
idx -> GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Int
idx
listSkipForward :: Searchable t
=> (e -> Bool)
-> L.GenericList n t e
-> L.GenericList n t e
listSkipForward :: forall (t :: * -> *) e n.
Searchable t =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipForward e -> Bool
test GenericList n t e
l = case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListForward IncludeCurrent
ExcludeCurrent e -> Bool
test GenericList n t e
l of
Maybe Int
Nothing -> GenericList n t e
l
Just Int
idx -> GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Int
idx
listSkipByPages :: (Searchable t, Foldable t, L.Splittable t, Ord n, RealFrac pages)
=> (e -> Bool)
-> pages
-> EventM n (L.GenericList n t e) ()
listSkipByPages :: forall (t :: * -> *) n pages e.
(Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) =>
(e -> Bool) -> pages -> EventM n (GenericList n t e) ()
listSkipByPages e -> Bool
test pages
p = if pages
p pages -> pages -> Bool
forall a. Eq a => a -> a -> Bool
== pages
0
then () -> EventM n (GenericList n t e) ()
forall a. a -> EventM n (GenericList n t e) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do
GenericList n t e
origL <- EventM n (GenericList n t e) (GenericList n t e)
forall s (m :: * -> *). MonadState s m => m s
get
pages -> EventM n (GenericList n t e) ()
forall (t :: * -> *) n m e.
(Foldable t, Splittable t, Ord n, RealFrac m) =>
m -> EventM n (GenericList n t e) ()
L.listMoveByPages pages
p
let (IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
searchList, IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
searchListOpposite) = if pages
p pages -> pages -> Bool
forall a. Ord a => a -> a -> Bool
< pages
0
then (IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListBackward, IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListForward)
else (IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListForward, IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListBackward)
(GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ())
-> (GenericList n t e -> GenericList n t e)
-> EventM n (GenericList n t e) ()
forall a b. (a -> b) -> a -> b
$ \GenericList n t e
l -> case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall {e} {n}.
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
searchList IncludeCurrent
IncludeCurrent e -> Bool
test GenericList n t e
l of
Maybe Int
Nothing -> case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall {e} {n}.
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
searchListOpposite IncludeCurrent
ExcludeCurrent e -> Bool
test GenericList n t e
l of
Maybe Int
Nothing -> GenericList n t e
origL
Just Int
idx -> GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Int
idx
Just Int
idx -> GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Int
idx
listSkipToBeginning :: (Searchable t, Foldable t, L.Splittable t)
=> (e -> Bool)
-> L.GenericList n t e
-> L.GenericList n t e
listSkipToBeginning :: forall (t :: * -> *) e n.
(Searchable t, Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipToBeginning e -> Bool
test GenericList n t e
l = case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListForward IncludeCurrent
IncludeCurrent e -> Bool
test (GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
L.listMoveToBeginning GenericList n t e
l) of
Maybe Int
Nothing -> GenericList n t e
l
Just Int
idx -> GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Int
idx
listSkipToEnd :: (Searchable t, Foldable t, L.Splittable t)
=> (e -> Bool)
-> L.GenericList n t e
-> L.GenericList n t e
listSkipToEnd :: forall (t :: * -> *) e n.
(Searchable t, Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listSkipToEnd e -> Bool
test GenericList n t e
l = case IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
forall (t :: * -> *) e n.
Searchable t =>
IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
skipListBackward IncludeCurrent
IncludeCurrent e -> Bool
test (GenericList n t e -> GenericList n t e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
L.listMoveToEnd GenericList n t e
l) of
Maybe Int
Nothing -> GenericList n t e
l
Just Int
idx -> GenericList n t e
l GenericList n t e
-> (GenericList n t e -> GenericList n t e) -> GenericList n t e
forall a b. a -> (a -> b) -> b
& (Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL ((Maybe Int -> Identity (Maybe Int))
-> GenericList n t e -> Identity (GenericList n t e))
-> Int -> GenericList n t e -> GenericList n t e
forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
?~ Int
idx
class Searchable (t :: * -> *) where
viewHead :: t a -> Maybe (a, t a)
viewLast :: t a -> Maybe (t a, a)
take :: Int -> t a -> t a
drop :: Int -> t a -> t a
instance Searchable Vector where
viewHead :: forall a. Vector a -> Maybe (a, Vector a)
viewHead = Vector a -> Maybe (a, Vector a)
forall a. Vector a -> Maybe (a, Vector a)
uncons
viewLast :: forall a. Vector a -> Maybe (Vector a, a)
viewLast = Vector a -> Maybe (Vector a, a)
forall a. Vector a -> Maybe (Vector a, a)
unsnoc
take :: forall a. Int -> Vector a -> Vector a
take = Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
V.take
drop :: forall a. Int -> Vector a -> Vector a
drop = Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
V.drop
instance Searchable Seq where
viewHead :: forall a. Seq a -> Maybe (a, Seq a)
viewHead Seq a
s = case Seq a -> ViewL a
forall a. Seq a -> ViewL a
S.viewl Seq a
s of
ViewL a
EmptyL -> Maybe (a, Seq a)
forall a. Maybe a
Nothing
a
a :< Seq a
s' -> (a, Seq a) -> Maybe (a, Seq a)
forall a. a -> Maybe a
Just (a
a, Seq a
s')
viewLast :: forall a. Seq a -> Maybe (Seq a, a)
viewLast Seq a
s = case Seq a -> ViewR a
forall a. Seq a -> ViewR a
S.viewr Seq a
s of
ViewR a
EmptyR -> Maybe (Seq a, a)
forall a. Maybe a
Nothing
Seq a
s' :> a
a -> (Seq a, a) -> Maybe (Seq a, a)
forall a. a -> Maybe a
Just (Seq a
s', a
a)
take :: forall a. Int -> Seq a -> Seq a
take = Int -> Seq a -> Seq a
forall a. Int -> Seq a -> Seq a
S.take
drop :: forall a. Int -> Seq a -> Seq a
drop = Int -> Seq a -> Seq a
forall a. Int -> Seq a -> Seq a
S.drop