FilterScan sends the contents of the pipe to the function filter, a line at a time, and produces the result. filter takes each line as a string and an [io.Writer] to write its output to. See [Pipe.Filter] for concurrency handling.
(filter func(string, io.Writer))
| 564 | // [io.Writer] to write its output to. See [Pipe.Filter] for concurrency |
| 565 | // handling. |
| 566 | func (p *Pipe) FilterScan(filter func(string, io.Writer)) *Pipe { |
| 567 | return p.Filter(func(r io.Reader, w io.Writer) error { |
| 568 | scanner := newScanner(r) |
| 569 | for scanner.Scan() { |
| 570 | filter(scanner.Text(), w) |
| 571 | } |
| 572 | return scanner.Err() |
| 573 | }) |
| 574 | } |
| 575 | |
| 576 | // First produces only the first n lines of the pipe's contents, or all the |
| 577 | // lines if there are less than n. If n is zero or negative, there is no output |