on master help sign in
Add Data.Cont module for continuations
commitadc550beda11ee27092093e8b563601897c63b5f authorHarendra Kumar <harendra@composewell.com> dateWed 12 Aug 2020, 00:52 (6 years ago) parentf234fd0
2 files changed+37
src/Streamly/Internal/Data/Cont.hs+36 streamly.cabal+1
src/Streamly/Internal/Data/Cont.hsnew file+36
@@ -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
streamly.cabal+1
@@ -385,6 +385,7 @@ library
385385 , Streamly.Internal.BaseCompat
386386 , Streamly.Internal.Control.Exception
387387 , Streamly.Internal.Control.Monad
388+ , Streamly.Internal.Data.Cont
388389 , Streamly.Internal.Data.Tuple.Strict
389390 , Streamly.Internal.Data.Maybe.Strict
390391 , Streamly.Internal.Data.Either.Strict