Idiomatic bidirectional Pipes with downstream state without loss

前端 未结 3 1541
陌清茗
陌清茗 2021-01-04 03:53

Say I have simple producer/consumer model where the consumer wants to pass back some state to the producer. For instance, let the downstream-flowing objects be objects we wa

3条回答
  •  Happy的楠姐
    2021-01-04 04:15

    The 'const's are where you are dropping the data. In order to get all the data, you probably want to do a push-based workflow as follows:

    writeObjects :: Object -> Proxy ObjectId Object () X IO r
    writeObjects obj = go 0 obj
      where
        go objid obj = do
            lift $ putStrLn $ "Wrote "++show obj
            obj' <- request objid
            go (objid + 1) obj'
    
    -- produceObjects as before
    
    main = void $ run $ produceObjects objects >>~ writeObjects
    

提交回复
热议问题