on dev help sign in
andThen
b9103f4Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+10−4
@@ -217,6 +217,7 @@ class IndexedMonadTransPQ pq where
217 :: Monad m
217 :: Monad m
218 => pq schema0 schema1 m (pq schema1 schema2 m y)
218 => pq schema0 schema1 m (pq schema1 schema2 m y)
219 -> pq schema0 schema2 m y
219 -> pq schema0 schema2 m y
220+ pqJoin pq = pq & pqBind id
220
221
221 -- | indexed analog of `=<<`
222 -- | indexed analog of `=<<`
222 pqBind
223 pqBind
@@ -231,6 +232,15 @@ class IndexedMonadTransPQ pq where
231 => pq schema1 schema2 m y
232 => pq schema1 schema2 m y
232 -> pq schema0 schema1 m x
233 -> pq schema0 schema1 m x
233 -> pq schema0 schema2 m y
234 -> pq schema0 schema2 m y
235+ pqThen pq2 pq1 = pq1 & pqBind (\ _ -> pq2)
236+
237+ -- | indexed analog of `<=<`
238+ pqAndThen
239+ :: Monad m
240+ => (y -> pq schema1 schema2 m z)
241+ -> (x -> pq schema0 schema1 m y)
242+ -> x -> pq schema0 schema2 m z
243+ pqAndThen g f x = pqBind g (f x)
234
244
235 -- | Safely embed a computation in a larger schema.
245 -- | Safely embed a computation in a larger schema.
236 pqEmbed
246 pqEmbed
@@ -253,14 +263,10 @@ instance IndexedMonadTransPQ PQ where
253 K x' <- x (K (unK conn))
263 K x' <- x (K (unK conn))
254 return $ K (f' x')
264 return $ K (f' x')
255
265
256− pqJoin pq = pq & pqBind id
257−
258 pqBind f (PQ x) = PQ $ \ conn -> do
266 pqBind f (PQ x) = PQ $ \ conn -> do
259 K x' <- x conn
267 K x' <- x conn
260 unPQ (f x') (K (unK conn))
268 unPQ (f x') (K (unK conn))
261
269
262− pqThen pq2 pq1 = pq1 & pqBind (\ _ -> pq2)
263−
264 pqEmbed (PQ pq) = PQ $ \ (K conn) -> do
270 pqEmbed (PQ pq) = PQ $ \ (K conn) -> do
265 K x <- pq (K conn)
271 K x <- pq (K conn)
266 return $ K x
272 return $ K x