<div dir="ltr">My first problem is that I was assuming each chunk was the entire line.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 30, 2017 at 12:08 AM, Cody Goodman <span dir="ltr"><<a href="mailto:codygman.consulting@gmail.com" target="_blank">codygman.consulting@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi all,<br><br></div>I have a function from Text -> Text which I want to apply to each line using pipes-text and pipes-group. <br><br><br></div>I'm pretty sure my pipe is not doing what I expect. I'm going back over the pipes tutorial now, but I think I could use some help figuring it out.<br><div><br>I have the following (buildable github project: <a href="https://github.com/codygman/fixedWidthToDelimited" target="_blank">https://github.com/codygman/<wbr>fixedWidthToDelimited</a>) code:<br><br>import Data.Monoid<br>import Pipes<br>import qualified Pipes.Text as Text<br>import qualified <a href="http://Pipes.Text.IO" target="_blank">Pipes.Text.IO</a> as Text<br>import System.IO<br>import Lens.Family<br>import qualified Pipes.Group as Group<br>import qualified Data.Text as T<br><br><br><br>appendAt :: Int -> T.Text -> T.Text -> (T.Text,T.Text)<br>appendAt i appendBS bs = let (first, rest) = T.splitAt i bs in (first <> appendBS <> rest,rest)<br><br>-- TODO figure out how to test a pipe (I'm sure pipes-text or any other libraries test their pipes)<br>toDelimPipe :: Monad m => [Int] -> Pipe T.Text T.Text m r<br>toDelimPipe offsets = do<br>    chunk <- await<br>    let text = (fixedWidthLine offsets) chunk<br>    if T.null text<br>      then (toDelimPipe offsets)<br>      else do yield text<br>              cat<br><br>fixedWidthLine :: [Int] -> T.Text -> T.Text<br>fixedWidthLine offsets bs = fst $ go offsets ("" :: T.Text,bs)<br>  where go :: [Int] -> (T.Text,T.Text) -> (T.Text,T.Text)<br>        go [] x = x<br>        go (x:xs) (acc,rest) = let (newAcc,newRest) = T.splitAt x rest in go xs (acc <> (fst $ appendAt x "|" newAcc),newRest)<br><br>{-<br>got:<br>runEffect $ over Text.lines (Group.maps (>-> toDelimPipe [2,2,2] )) (Text.fromLazy (LT.replicate 2 "x" <> LT.replicate 2 "y" <> LT.replicate 2 "z")) >-> Text.stdout<br>xx|||yyzz<br><br>Expected:<br><br>xx|yy|zz|<br><br>When I use fixedWidthLine alone with the same offsets I get:<br><br>λ> fixedWidthLine [2,2,2] (T.replicate 2 "x" <> T.replicate 2 "y" <> T.replicate 2 "z")<br>"xx|yy|zz|"<br><br>I think my pipe is wrong<br><br>-}<br><br></div></div>
</blockquote></div><br></div>