refactor(set): minor refactor using foldMap

This commit is contained in:
Steffen Jost 2023-09-06 16:04:41 +00:00
parent bf53c639e7
commit 30e5694712
2 changed files with 6 additions and 6 deletions

View File

@ -80,7 +80,7 @@ import qualified Data.Text.Lazy.Builder as Text.Builder
import Data.Monoid (Last(..))
import Utils (commaSeparatedText)
import Utils.Set (concatMapSet)
-- import Utils.Set (concatMapSet)
{-# 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)
-- | 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)
-> (t -> E.SqlExpr (E.Value b)) -- ^ getter from query to searched element
-> t -- ^ query row
@ -343,7 +343,7 @@ mkContainsFilterWithSet :: (E.SqlString b, Ord b)
-> E.SqlExpr (E.Value Bool)
mkContainsFilterWithSet cast lenslike row criterias
| 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
mkContainsFilterWithComma :: (E.SqlString b, Ord b)
@ -352,7 +352,7 @@ mkContainsFilterWithComma :: (E.SqlString b, Ord b)
-> t -- ^ query row
-> Set.Set Text -- ^ needle collection
-> E.SqlExpr (E.Value Bool)
mkContainsFilterWithComma cast lenslike row (concatMapSet commaSeparatedText -> criterias)
mkContainsFilterWithComma cast lenslike row (foldMap commaSeparatedText -> criterias)
| Set.null criterias = true
| otherwise = any (hasInfix $ lenslike row) (E.val . cast <$> Set.toList criterias)
@ -363,7 +363,7 @@ mkContainsFilterWithCommaPlus :: (E.SqlString b, Ord b)
-> t -- ^ query row
-> Set.Set Text -- ^ needle collection
-> 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 compulsories = cond_optional
| Set.null alternatives = cond_compulsory

View File

@ -58,7 +58,7 @@ setMapMaybe f = Set.fromList . mapMaybe f . Set.toList
concatMapSet :: Ord b => (a -> Set b) -> Set a -> Set b
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.
setSymmDiff :: Ord a => Set a -> Set a -> Set a