servant-util-0.2: Servant servers utilities.
Safe HaskellNone
LanguageHaskell2010

Servant.Util.Dummy.Filtering

Description

Implements plain filtering.

Example:

filteringSpecApp
    :: MyObject
    -> FilteringSpecApp
        DummyFilteringBackend
        [ "id" ?: 'AutoFilter Course
        , "desc" ?: 'AutoFilter Text
        , "isAwesome" ?: 'ManualFilter Bool
        ]
filteringSpecApp obj =
    filterOn_ "id" (id obj) .*.
    filterOn_ "desc" (desc obj) .*.
    customFilter_ @"isAwesome" (== (awesomeness obj > 42)) .*.
    HNil

Annotating filterOn and customFilter calls with parameter name is fully optional and used only to visually disambiguate filters of the same types.

Next, you use matches to check whether a value matches user-provided filters.

filterObjects filters = filter (matches filters . filteringSpecApp) allObjects
Synopsis

Documentation

matches :: (backend ~ DummyFilteringBackend, BackendApplySomeFilter backend params) => FilteringSpec params -> FilteringSpecApp backend params -> Bool Source #

Applies a whole filtering specification to a set of response fields. Resulting value can be put to filter function.

filterBySpec :: (backend ~ DummyFilteringBackend, BackendApplySomeFilter backend params) => FilteringSpec params -> (a -> FilteringSpecApp backend params) -> [a] -> [a] Source #

Filters given values by a filtering specification.

filterOn :: forall name backend a. Typeable a => AutoFilteredValue backend a -> FilteringApp backend ('TyNamedParam name ('AutoFilter a)) Source #

Implement an automatic filter. User-provided filtering operation will do filter on this value.

manualFilter :: forall name backend a. Typeable a => (a -> MatchPredicate backend) -> FilteringApp backend ('TyNamedParam name ('ManualFilter a)) Source #

Implement a manual filter. You are provided with a value which user supplied and so you have to construct a Beam predicate involving that value and relevant response fields.