@@ -0,0 +1,36 @@
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
9+-- Continuation style utilities.
11+module Streamly.Internal.Data.Cont
16+import Control.Monad.Cont (runCont, cont)
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@.
24+-- You can read the definition as:
26+-- > contListMap f g = \xs final ->
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