Safe Haskell | None |
---|---|
Language | Haskell2010 |
Implements plain lexicographical sorting.
Example:
sortingSpecApp
:: MyObject
-> SortingSpecApp
DummySortingBackend
[ "id" ?: Int
, "desc" ?: Text
]
sortingSpecApp obj =
fieldSort "id" (id obj) .*.
fieldSort
"desc" (desc obj) .*.
HNil
Next, you use sortBySpec
to apply sorting.
sortObjects sorting = filter (sortBySpec sorting . sortingSpecApp) allObjects
Synopsis
- type SortingSpecApp backend (allParams :: [TyNamedParam *]) = HList (SortingApp backend) allParams
- fieldSort :: forall name a backend. (SortingBackend backend, SortedValueConstraint backend a) => SortedValue backend a -> SortingApp backend ('TyNamedParam name a)
- sortBySpec :: (backend ~ DummySortingBackend, allParams ~ AllSortingParams provided base, ApplyToSortItem backend allParams) => SortingSpec provided base -> (a -> SortingSpecApp backend allParams) -> [a] -> [a]
Documentation
type SortingSpecApp backend (allParams :: [TyNamedParam *]) = HList (SortingApp backend) allParams Source #
List of SortingApp
functions. Describes how to apply SortingSpec params
(each of possible SortingItem
) to an SQL query.
Instance of this type can be created using fieldSort
function. For example:
sortingSpecApp :: SortingSpecApp ["course" ?: Course, "desc" ?: Text]
sortingSpecApp =
fieldSort "course" courseField .*.
fieldSort
"desc" descField .*.
HNil
Annotating fieldSort
call with parameter name is not mandatory but recommended
to prevent possible mistakes in fieldSort
s ordering.
fieldSort :: forall name a backend. (SortingBackend backend, SortedValueConstraint backend a) => SortedValue backend a -> SortingApp backend ('TyNamedParam name a) Source #
sortBySpec :: (backend ~ DummySortingBackend, allParams ~ AllSortingParams provided base, ApplyToSortItem backend allParams) => SortingSpec provided base -> (a -> SortingSpecApp backend allParams) -> [a] -> [a] Source #
Applies a whole filtering specification to a set of response fields.
Resulting value can be put to filter
function.