<html><head><meta http-equiv="Content-Type" content="text/html charset=gb2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Thanks very much</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">在 2017年7月21日,下午3:17,Michael Snoyman <<a href="mailto:michael@snoyman.com" class="">michael@snoyman.com</a>> 写道:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'll preface by saying this probably indicates that the API for concatMapAccumC should be slightly different than it is currently.<div class=""><br class=""></div><div class="">The problem is that there is no way to convert the final accumulator value into output, and therefore when the input stream ends, that accumulator is simply dropped. One solution (pretty hacky) is to wrap all of the lines in a `Just` and then send in a final `Nothing` value to indicate that the stream is ended. This would look like:</div><div class=""><br class=""></div><div class=""><a href="https://gist.github.com/snoyberg/6537120fca2e9b8944e41fe60d285793" class="">https://gist.github.com/snoyberg/6537120fca2e9b8944e41fe60d285793</a><br class=""></div><div class=""><br class=""></div><div class="">Another option is to simply use the conduit primitives (await and yield) directly:</div><div class=""><br class=""></div><div class=""><a href="https://gist.github.com/snoyberg/bd58030db9b9c90f9e1fcf8b31ea10e9" class="">https://gist.github.com/snoyberg/bd58030db9b9c90f9e1fcf8b31ea10e9</a><br class=""></div><div class=""><br class=""></div><div class="">I'd lean towards the latter.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Jul 20, 2017 at 9:34 AM, jun zhang <span dir="ltr" class=""><<a href="mailto:zhangjun.julian@gmail.com" target="_blank" class="">zhangjun.julian@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div style="word-wrap:break-word" class=""><div class="">Dear all </div><div class=""><br class=""></div><div class="">the runnable example code is as blow</div><div class=""><br class=""></div><div class="">==============================<wbr class="">==============================<wbr class="">=======</div><div class=""><div class="">import Conduit</div><div class="">import Text.Regex (matchRegex,mkRegex,Regex)</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">loghead = mkRegex "^([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-<wbr class="">9]{3} )"</div><div class="">-- "2015-01-25 00:04:18,840"</div><div class=""><br class=""></div><div class="">logMerge::Regex->String-><wbr class="">String->(String,[String])</div><div class="">logMerge logregex str accum =</div><div class="">    case  matchRegex logregex  str of</div><div class="">        Just _ ->  (str,[(accum++"\n")])</div><div class="">        Nothing -> case null accum of</div><div class="">            True ->  (str,[])</div><div class="">            False ->  (accum ++ "<br>" ++ str,[])</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">runMerge::String->String->IO ()</div><div class="">runMerge infile outfile =</div><div class="">    runResourceT $ sourceFile infile  $= linesUnboundedC $= concatMapAccumC (logMerge loghead ) "" $$  sinkFile outfile</div></div><div class=""><br class=""></div><div class="">==============================<wbr class="">==============================<wbr class="">====</div><div class=""><br class=""></div><div class="">the example input file is </div><div class="">---------</div><div class=""><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |  | errorCode: toString() = null</div><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |   codsexception.getErrorCode(): toString() </div><div class="">{</div><div class="">    errorCode = "UNEXPECTED_PROBLEM"</div><div class="">    severity = ""</div><div class="">}</div><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |  | </div><div class="">2015-01-25 00:03:45,331 | DEBUG | WebContainer : 20  |  | </div></div><div class="">---------</div><div class=""><br class=""></div><div class="">the expected output is </div><div class=""><div class="">---------</div><div class=""><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |  | errorCode: toString() = null</div><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |   codsexception.getErrorCode(): toString() <br>{<br>    errorCode =<br>"UNEXPECTED_PROBLEM"<br>    severity = ""<br>}</div><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |  | </div><div class="">2015-01-25 00:03:45,331 | DEBUG | WebContainer : 20  |  | </div></div><div class="">---------</div></div><div class=""><br class=""></div><div class="">the actual output is blow, missing the last line of log</div><div class=""><div class="">---------</div><div class=""><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |  | errorCode: toString() = null</div><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |   codsexception.getErrorCode(): toString() <br>{<br>    errorCode =<br>"UNEXPECTED_PROBLEM"<br>    severity = ""<br>}</div><div class="">2015-01-25 00:03:44,331 | DEBUG | WebContainer : 20  |  | </div></div><div class="">---------</div></div><div class=""><br class=""></div><div class="">Thanks </div><div class=""><div class="h5"><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">在 2017年7月19日,下午7:50,Michael Snoyman <<a href="mailto:michael@snoyman.com" target="_blank" class="">michael@snoyman.com</a>> 写道:</div><br class="m_-3164116447155318800Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'm afraid I doon't follow what it meant by the stream here. Could you provide a complete, runnable example and indicate what the expected and actual output are?<div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jul 17, 2017 at 5:48 AM, jun zhang <span dir="ltr" class=""><<a href="mailto:zhangjun.julian@gmail.com" target="_blank" class="">zhangjun.julian@gmail.<wbr class="">com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Dear cafes<br class=""><br class="">I use Conduit to parse a huge file. And I need merge lines by condition.<br class=""><br class="">I find the concatMapAccumC can do that and I write a demo as blow(with conduit-combinators-1.0.6,lts-<wbr class="">6.18).<br class="">The problem is if the last item didn’t make condition true, the data only keep in the accum but missing in stream.<br class=""><br class="">Any one can give me some advises?<br class=""><br class="">Thanks<br class=""><br class=""><br class="">----------------------------<br class="">import Conduit<br class=""><br class="">test'::Int->Int->(Int,[Int])<br class="">test' a s = case (a+s) > 5 of<br class="">    True -> (0,[a+s])<br class="">    False -> (a+s,[])<br class=""><br class="">testlog::IO [Int]<br class="">testlog = runConduit $ (yieldMany [1,2,3,4,5,6,3]) $=  (concatMapAccumC test' 0 ) $$ sinkList<br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><br class="">______________________________<wbr class="">_________________<br class="">Haskell-Cafe mailing list<br class="">To (un)subscribe, modify options or view archives go to:<br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bi<wbr class="">n/mailman/listinfo/haskell-caf<wbr class="">e</a><br class="">Only members subscribed via the mailman list are allowed to post.</blockquote></div><br class=""></div></div></div></blockquote></div></div></div></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>