From 03795115450a8aa957d75dce711b047af10605db Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 23 Jul 2019 09:56:10 +0200 Subject: [PATCH] refactor(esqueleto-utils): define any and all in terms of or and and --- src/Database/Esqueleto/Utils.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Database/Esqueleto/Utils.hs b/src/Database/Esqueleto/Utils.hs index 02846faec..6ddf7edd3 100644 --- a/src/Database/Esqueleto/Utils.hs +++ b/src/Database/Esqueleto/Utils.hs @@ -67,15 +67,13 @@ or = F.foldr (E.||.) false -- | Given a test and a set of values, check whether anyone succeeds the test -- WARNING: SQL leaves it explicitely unspecified whether `||` is short curcuited (i.e. lazily evaluated) -any :: Foldable f => - (a -> E.SqlExpr (E.Value Bool)) -> f a -> E.SqlExpr (E.Value Bool) -any test = F.foldr (\needle acc -> acc E.||. test needle) false +any :: MonoFoldable f => (Element f -> E.SqlExpr (E.Value Bool)) -> f -> E.SqlExpr (E.Value Bool) +any test = or . map test . otoList -- | Given a test and a set of values, check whether all succeeds the test -- WARNING: SQL leaves it explicitely unspecified whether `&&` is short curcuited (i.e. lazily evaluated) -all :: Foldable f => - (a -> E.SqlExpr (E.Value Bool)) -> f a -> E.SqlExpr (E.Value Bool) -all test = F.foldr (\needle acc -> acc E.&&. test needle) true +all :: MonoFoldable f => (Element f -> E.SqlExpr (E.Value Bool)) -> f -> E.SqlExpr (E.Value Bool) +all test = and . map test . otoList -- Allow usage of Tuples as DbtRowKey, i.e. SqlIn instances for tuples