Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Functions that brick event handlers can use to search forward or backward for certain kinds of items in brick list.
For example, in the above demo program, you can search forward or backward for a list element that is not a separator.
Synopsis
- type IncludeCurrent = Bool
- searchListForward :: Searchable t => IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
- searchListBackward :: Searchable t => IncludeCurrent -> (e -> Bool) -> GenericList n t e -> Maybe Int
- listSearchBy :: (Searchable t, Foldable t, Splittable t) => (e -> Bool) -> Int -> GenericList n t e -> GenericList n t e
- listSearchUp :: Searchable t => (e -> Bool) -> GenericList n t e -> GenericList n t e
- listSearchDown :: Searchable t => (e -> Bool) -> GenericList n t e -> GenericList n t e
- listSearchByPages :: (Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) => (e -> Bool) -> pages -> EventM n (GenericList n t e) ()
- listSearchPageUp :: (Searchable t, Foldable t, Splittable t, Ord n) => (e -> Bool) -> EventM n (GenericList n t e) ()
- listSearchPageDown :: (Searchable t, Foldable t, Splittable t, Ord n) => (e -> Bool) -> EventM n (GenericList n t e) ()
- listSearchFromBeginning :: (Searchable t, Foldable t, Splittable t) => (e -> Bool) -> GenericList n t e -> GenericList n t e
- listSearchFromEnd :: (Searchable t, Foldable t, Splittable t) => (e -> Bool) -> GenericList n t e -> GenericList n t e
- listShowTheTop :: Searchable t => (e -> Bool) -> EventM n (GenericList n t e) ()
- listShowTheBottom :: Searchable t => (e -> Bool) -> EventM n (GenericList n t e) ()
- class Searchable (t :: * -> *) where
Types
type IncludeCurrent = Bool Source #
Should the search include the current location?
Low-level functions
These functions are used in list manipulation and list display.
:: Searchable t | |
=> IncludeCurrent | |
-> (e -> Bool) | The test |
-> GenericList n t e | |
-> Maybe Int | The first element index that passes the test |
Search forward for the first element index that passes the test
:: Searchable t | |
=> IncludeCurrent | |
-> (e -> Bool) | The test |
-> GenericList n t e | |
-> Maybe Int | The first element index that passes the test |
Search backward for the first element index that passes the test
List manipulation
:: (Searchable t, Foldable t, Splittable t) | |
=> (e -> Bool) | The test |
-> Int | The amount of list elements to move by |
-> GenericList n t e | |
-> GenericList n t e |
Move by an amount of list elements in the list. If the amount to move by is 0, no change is made. Otherwise, call
listMoveBy
.
The element chosen by listMoveBy
is included in the search.
After calling listMoveBy
, if the amount to move by was positive, search forward for the first element that passes
the test. If forward search fails, search backward for the first such element. If backward search fails too, no
change is made.
After calling listMoveBy
, if the amount to move by was negative, search backward for the first element that
passes the test. If backward search fails, search forward for the first such element. If forward search fails too, no
change is made.
:: Searchable t | |
=> (e -> Bool) | The test |
-> GenericList n t e | |
-> GenericList n t e |
Search backward for the first element that passes the test.
The current element is not included in the search.
If backward search fails, no change is made.
:: Searchable t | |
=> (e -> Bool) | The test |
-> GenericList n t e | |
-> GenericList n t e |
Search forward for the first element that passes the test.
The current element is not included in the search.
If forward search fails, no change is made.
:: (Searchable t, Foldable t, Splittable t, Ord n, RealFrac pages) | |
=> (e -> Bool) | The test |
-> pages | Pages to move by |
-> EventM n (GenericList n t e) () |
Move by a (fractional) number of pages in the list. If the number of pages to move by is 0, no change is made.
Otherwise, call listMoveByPages
with the number of pages to move by.
The element chosen by listMoveByPages
is included in the search.
After calling listMoveByPages
, if the number of pages to move by was positive, search forward for the first
element that passes the test. If forward search fails, then search backward for the first such element. If backward
search fails too, cancel movements made by this function.
After calling listMoveByPages
, if the number of pages to move by was negative, search backward for the first
element that passes the test. If backward search fails, then search forward for the first such element. If forward
search fails too, cancel movements made by this function.
:: (Searchable t, Foldable t, Splittable t, Ord n) | |
=> (e -> Bool) | The test |
-> EventM n (GenericList n t e) () |
Move up one page, and search backward for the first element that passes the test.
The element chosen by moving up one page is included in the search.
If backward search fails, search forward for the first element that passes the test.
If forward search fails too, cancel movements made by this function.
:: (Searchable t, Foldable t, Splittable t, Ord n) | |
=> (e -> Bool) | The test |
-> EventM n (GenericList n t e) () |
Move down one page, and search forward for the first element that passes the test.
The element chosen by moving down one page is included in the search.
If forward search fails, search backward for the first element that passes the test.
If backward search fails too, cancel movements made by this function.
listSearchFromBeginning Source #
:: (Searchable t, Foldable t, Splittable t) | |
=> (e -> Bool) | The test |
-> GenericList n t e | |
-> GenericList n t e |
From the first element, search forward for the first element that passes the test.
The first element is included in the search.
If forward search fails, no change is made.
:: (Searchable t, Foldable t, Splittable t) | |
=> (e -> Bool) | The test |
-> GenericList n t e | |
-> GenericList n t e |
From the last element, search backward for the first element that passes the test.
The last element is included in the search.
If backward search fails, no change is made.
List display
List display functions do not change the current list element.
:: Searchable t | |
=> (e -> Bool) | The test |
-> EventM n (GenericList n t e) () |
If searching backward for a list element that passes the test fails, show as many list elements as possible above the current element.
The current list element is not included in the backward search.
Call this after moving backward by calling one of list manipulation functions.
:: Searchable t | |
=> (e -> Bool) | The test |
-> EventM n (GenericList n t e) () |
If searching forward for a list element that passes the test fails, show as many list elements as possible below the current element.
The current list element is not included in the forward search.
Call this after moving forward by calling one of list manipulation functions.
Classes
class Searchable (t :: * -> *) where Source #
Functions for searching elements.
viewHead :: t a -> Maybe (a, t a) Source #
Get the head and the rest
viewLast :: t a -> Maybe (t a, a) Source #
Get the last element and the rest
take :: Int -> t a -> t a Source #
Take a number of elements from the beginning
drop :: Int -> t a -> t a Source #
Drop a number of elements from the beginning
Instances
Searchable Seq Source # | O(1) for viewHead and viewLast. O(log(min(i,n-i))) for take and drop. |
Searchable Vector Source # | O(1) for all operations |