refactor(set): minor refactor using foldMap
This commit is contained in:
parent
bf53c639e7
commit
30e5694712
@ -80,7 +80,7 @@ import qualified Data.Text.Lazy.Builder as Text.Builder
|
|||||||
import Data.Monoid (Last(..))
|
import Data.Monoid (Last(..))
|
||||||
|
|
||||||
import Utils (commaSeparatedText)
|
import Utils (commaSeparatedText)
|
||||||
import Utils.Set (concatMapSet)
|
-- import Utils.Set (concatMapSet)
|
||||||
|
|
||||||
|
|
||||||
{-# ANN any ("HLint: ignore Use any" :: String) #-}
|
{-# ANN any ("HLint: ignore Use any" :: String) #-}
|
||||||
@ -335,7 +335,7 @@ mkContainsFilterWith cast lenslike row criterias
|
|||||||
| otherwise = any (hasInfix $ lenslike row) (E.val . cast <$> Set.toList criterias)
|
| otherwise = any (hasInfix $ lenslike row) (E.val . cast <$> Set.toList criterias)
|
||||||
|
|
||||||
-- | like `mkContainsFilterWith` but allows conversion to produce multiple needles
|
-- | like `mkContainsFilterWith` but allows conversion to produce multiple needles
|
||||||
mkContainsFilterWithSet :: (E.SqlString b, Ord b)
|
mkContainsFilterWithSet :: (E.SqlString b, Ord b, Ord a)
|
||||||
=> (a -> Set.Set b)
|
=> (a -> Set.Set b)
|
||||||
-> (t -> E.SqlExpr (E.Value b)) -- ^ getter from query to searched element
|
-> (t -> E.SqlExpr (E.Value b)) -- ^ getter from query to searched element
|
||||||
-> t -- ^ query row
|
-> t -- ^ query row
|
||||||
@ -343,7 +343,7 @@ mkContainsFilterWithSet :: (E.SqlString b, Ord b)
|
|||||||
-> E.SqlExpr (E.Value Bool)
|
-> E.SqlExpr (E.Value Bool)
|
||||||
mkContainsFilterWithSet cast lenslike row criterias
|
mkContainsFilterWithSet cast lenslike row criterias
|
||||||
| Set.null criterias = true
|
| Set.null criterias = true
|
||||||
| otherwise = any (hasInfix $ lenslike row) (E.val <$> Set.toList (concatMapSet cast criterias))
|
| otherwise = any (hasInfix $ lenslike row) (E.val <$> Set.toList (foldMap cast criterias))
|
||||||
|
|
||||||
-- | like `mkContainsFilterWithSet` but fixed to comma separated Texts
|
-- | like `mkContainsFilterWithSet` but fixed to comma separated Texts
|
||||||
mkContainsFilterWithComma :: (E.SqlString b, Ord b)
|
mkContainsFilterWithComma :: (E.SqlString b, Ord b)
|
||||||
@ -352,7 +352,7 @@ mkContainsFilterWithComma :: (E.SqlString b, Ord b)
|
|||||||
-> t -- ^ query row
|
-> t -- ^ query row
|
||||||
-> Set.Set Text -- ^ needle collection
|
-> Set.Set Text -- ^ needle collection
|
||||||
-> E.SqlExpr (E.Value Bool)
|
-> E.SqlExpr (E.Value Bool)
|
||||||
mkContainsFilterWithComma cast lenslike row (concatMapSet commaSeparatedText -> criterias)
|
mkContainsFilterWithComma cast lenslike row (foldMap commaSeparatedText -> criterias)
|
||||||
| Set.null criterias = true
|
| Set.null criterias = true
|
||||||
| otherwise = any (hasInfix $ lenslike row) (E.val . cast <$> Set.toList criterias)
|
| otherwise = any (hasInfix $ lenslike row) (E.val . cast <$> Set.toList criterias)
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ mkContainsFilterWithCommaPlus :: (E.SqlString b, Ord b)
|
|||||||
-> t -- ^ query row
|
-> t -- ^ query row
|
||||||
-> Set.Set Text -- ^ needle collection
|
-> Set.Set Text -- ^ needle collection
|
||||||
-> E.SqlExpr (E.Value Bool)
|
-> E.SqlExpr (E.Value Bool)
|
||||||
mkContainsFilterWithCommaPlus cast lenslike row (concatMapSet commaSeparatedText -> criterias)
|
mkContainsFilterWithCommaPlus cast lenslike row (foldMap commaSeparatedText -> criterias)
|
||||||
| Set.null criterias = true
|
| Set.null criterias = true
|
||||||
| Set.null compulsories = cond_optional
|
| Set.null compulsories = cond_optional
|
||||||
| Set.null alternatives = cond_compulsory
|
| Set.null alternatives = cond_compulsory
|
||||||
|
|||||||
@ -58,7 +58,7 @@ setMapMaybe f = Set.fromList . mapMaybe f . Set.toList
|
|||||||
|
|
||||||
concatMapSet :: Ord b => (a -> Set b) -> Set a -> Set b
|
concatMapSet :: Ord b => (a -> Set b) -> Set a -> Set b
|
||||||
concatMapSet f = Set.foldl ((. f) . (<>)) mempty
|
concatMapSet f = Set.foldl ((. f) . (<>)) mempty
|
||||||
-- concatMapSet f = foldMap f --- requires Ord a as well
|
-- concatMapSet f = foldMap f --- requires Ord a as well, which we ought to have anyway
|
||||||
|
|
||||||
-- | Symmetric difference of two sets.
|
-- | Symmetric difference of two sets.
|
||||||
setSymmDiff :: Ord a => Set a -> Set a -> Set a
|
setSymmDiff :: Ord a => Set a -> Set a -> Set a
|
||||||
|
|||||||
Reference in New Issue
Block a user