github.com/jwowillo/pipe@v1.2.0/example_process_and_consume_test.go (about)

     1  package pipe_test
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/jwowillo/pipe"
     7  )
     8  
     9  func Example_processAndConsume() {
    10  	p := pipe.New(
    11  		pipe.StageFunc(func(x pipe.Item) pipe.Item {
    12  			return x.(string) + "a"
    13  		}),
    14  		pipe.StageFunc(func(x pipe.Item) pipe.Item {
    15  			return x.(string) + "b"
    16  		}),
    17  		pipe.StageFunc(func(x pipe.Item) pipe.Item {
    18  			return x.(string) + "c"
    19  		}),
    20  	)
    21  	f := pipe.ConsumerFunc(func(x pipe.Item) {
    22  		fmt.Println(x)
    23  	})
    24  	pipe.ProcessAndConsume(p, f, "")
    25  	// Output:
    26  	// abc
    27  }