From 41698518c952815624b8c3b247573201b275b4ca Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 8 Jul 2014 08:44:02 +1000 Subject: [PATCH] Rename keyE to valJ and fix implementation. As Felipe points out in the PR comments, the implementation can be simplified to "val . unValue" but the type signature on the function still prevents anything non-sensical happening. See: https://github.com/prowdsponsor/esqueleto/pull/69 --- src/Database/Esqueleto.hs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Database/Esqueleto.hs b/src/Database/Esqueleto.hs index 490a79c..c4c09b4 100644 --- a/src/Database/Esqueleto.hs +++ b/src/Database/Esqueleto.hs @@ -81,7 +81,7 @@ module Database.Esqueleto -- * Helpers , valkey - , keyE + , valJ -- * Re-exports -- $reexports @@ -377,14 +377,16 @@ valkey :: Esqueleto query expr backend => valkey = val . Key . PersistInt64 --- | Given a value, lift the Key for that value into the query expression. -keyE :: Esqueleto query expr backend => +-- | @valJ@ is like @val@ but for something that is already a @Value@. The use +-- case it was written for was, given a @Value@ lift the @Key@ for that @Value@ +-- into the query expression in a type safe way. However, the implementation is +-- more generic than that so we call it @valJ@. +-- Its important to note that the input entity and the output entity are +-- constrained to be the same by the type signature on the function. +-- () +valJ :: Esqueleto query expr backend => Value (Key entity) -> expr (Value (Key entity)) -keyE v = - valkey $ - case (unKey . unValue) v of - PersistInt64 x -> x - _ -> error "Esqueleto.keyE: Impossible!" +valJ = val . unValue ----------------------------------------------------------------------