on e4e1d25 help sign in
36 lines 1.0 kB history raw
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--
11module Streamly.Internal.Data.Cont
12 ( contListMap
13 )
14where
16import 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@.
21--
22-- /Internal/
24-- You can read the definition as:
25--
26-- > contListMap f g = \xs final ->
27--
28contListMap ::
29 (a -> (b -> r) -> r) -- transform a -> b
30 -> ([b] -> (c -> r) -> r) -- transform [b] -> c
31 -> ([a] -> (c -> r) -> r) -- transform [a] -> c
32contListMap 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