You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: testfilter.go
    path of file: ./repos/cockroach/pkg/cmd/bazci/testfilter
    
    the code of the file until where you have to start completion: // Copyright 2019 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this sof
    
func FilterAndWrite(in io.Reader, out io.Writer, modesSequence []string) error {
	type pipe struct {
		reader io.Reader
		writer io.Writer
	}
	pipesArray := make([]pipe, len(modesSequence))
	for idx := range modesSequence {
		if idx == 0 {
			pipesArray[idx].reader = in
		}
		if idx == len(modesSequence)-1 {
			pipesArray[idx].writer = out
		} else {
			reader, writer := io.Pipe()
			pipesArray[idx].writer = writer
			pipesArray[idx+1].reader = reader
		}
	}
	var eg errgroup.Group
	for idx, mode := range modesSequence {
		idx := idx
		mode := mode
		eg.Go(func() error {
			if err := filter(pipesArray[idx].reader, pipesArray[idx].writer, mode); err != nil {
				return err
			}
			if idx != 0 {
				pipe := pipesArray[idx].reader.(*io.PipeReader)
				if err := pipe.Close(); err != nil {
					return err
				}
			}
			if idx != len(modesSequence)-1 {
				pipe := pipesArray[idx].writer.(*io.PipeWriter)
				if err := pipe.Close(); err != nil {
					return err
				}
			}
			return nil
		})
	}
	return eg.Wait()
}