@@ -0,0 +1,36 @@
1+-- |
2+-- Module : Streamly.Internal.Data.Cont
3+-- Copyright : (c) 2020 Composewell Technologies
4+-- License : BSD-3-Clause
5+-- Maintainer : streamly@composewell.com
6+-- Stability : experimental
7+-- Portability : GHC
8+--
9+-- Continuation style utilities.
10+--
11+module Streamly.Internal.Data.Cont
12+ ( contListMap
13+ )
14+where
15+
16+import Control.Monad.Cont (runCont, cont)
17+
18+-- | Given a continuation based transformation from @a@ to @b@ and a
19+-- continuation based transformation from @[b]@ to @c@, make continuation based
20+-- transformation from @[a]@ to @c@.
21+--
22+-- /Internal/
23+
24+-- You can read the definition as:
25+--
26+-- > contListMap f g = \xs final ->
27+--
28+contListMap ::
29+ (a -> (b -> r) -> r) -- transform a -> b
30+ -> ([b] -> (c -> r) -> r) -- transform [b] -> c
31+ -> ([a] -> (c -> r) -> r) -- transform [a] -> c
32+contListMap f g xs final =
33+ let bconts = fmap (cont . f) xs -- [Cont b]
34+ blistCont = sequence bconts -- Cont [b]
35+ k ys = g ys final -- [b] -> r
36+ in runCont blistCont k -- r