func ExampleCommand_withError() { err := stream.Run(stream.Command("no_such_command")) if err == nil { fmt.Println("execution of missing command succeeded unexpectedly") } // Output: }
func ExampleFind_error() { err := stream.Run(stream.Find("/no_such_dir")) if err == nil { fmt.Println("stream.Find did not return expected error") } // Output: }
func ExampleSample() { stream.Run( stream.Numbers(100, 200), stream.Sample(4), stream.WriteLines(os.Stdout), ) // Output not checked since it is non-deterministic. }
func BenchmarkFive(b *testing.B) { f := stream.FilterFunc(func(arg stream.Arg) error { for s := range arg.In { arg.Out <- s } return nil }) stream.Run(stream.Repeat("", b.N), f, f, f, f) }
func ExampleXargs() { stream.Run( stream.Numbers(1, 5), stream.Xargs("echo"), stream.WriteLines(os.Stdout), ) // Output: // 1 2 3 4 5 }
func ExampleItems() { stream.Run( stream.Items("hello", "world"), stream.WriteLines(os.Stdout), ) // Output: // hello // world }
func ExampleCommand() { stream.Run( stream.Numbers(1, 100), stream.Command("wc", "-l"), stream.WriteLines(os.Stdout), ) // Output: // 100 }
func ExampleCat() { stream.Run( stream.Cat("stream_test.go"), stream.Grep("^func ExampleCat"), stream.WriteLines(os.Stdout), ) // Output: // func ExampleCat() { }
func ExampleColumns() { stream.Run( stream.Items("hello world"), stream.Columns(2, 3, 1), stream.WriteLines(os.Stdout), ) // Output: // world hello }
func ExampleNumberLines() { stream.Run( stream.Items("a", "b"), stream.NumberLines(), stream.WriteLines(os.Stdout), ) // Output: // 1 a // 2 b }
func ExampleWriteLines() { stream.Run( stream.Numbers(1, 3), stream.WriteLines(os.Stdout), ) // Output: // 1 // 2 // 3 }
func ExampleFindFilter_SkipDirIf() { stream.Run( stream.Find(".").SkipDirIf(func(d string) bool { return d == ".git" }), stream.Grep("x"), stream.WriteLines(os.Stdout), ) // Output: // regexp.go // xargs.go }
func ExampleFind() { stream.Run( stream.Find(".").IfMode(os.FileMode.IsRegular), stream.Grep("stream"), stream.WriteLines(os.Stdout), ) // Output: // stream.go // stream_test.go }
func ExampleDropFirst() { stream.Run( stream.Numbers(1, 10), stream.DropFirst(8), stream.WriteLines(os.Stdout), ) // Output: // 9 // 10 }
func ExampleLast() { stream.Run( stream.Numbers(1, 10), stream.Last(2), stream.WriteLines(os.Stdout), ) // Output: // 9 // 10 }
func ExampleReverse() { stream.Run( stream.Items("a", "b"), stream.Reverse(), stream.WriteLines(os.Stdout), ) // Output: // b // a }
func ExampleUniqWithCount() { stream.Run( stream.Items("a", "b", "b", "c"), stream.UniqWithCount(), stream.WriteLines(os.Stdout), ) // Output: // 1 a // 2 b // 1 c }
func ExampleRun() { err := stream.Run( stream.Items("line 1", "line 2"), stream.WriteLines(os.Stdout), ) fmt.Println("error:", err) // Output: // line 1 // line 2 // error: <nil> }
func ExampleSorter_By() { stream.Run( stream.Items("bananas", "apples", "pears"), stream.Sort().By(func(a, b string) bool { return len(a) < len(b) }), stream.WriteLines(os.Stdout), ) // Output: // pears // apples // bananas }
func ExampleFirst() { stream.Run( stream.Numbers(1, 10), stream.First(3), stream.WriteLines(os.Stdout), ) // Output: // 1 // 2 // 3 }
func ExampleSampleWithSeed() { stream.Run( stream.Numbers(1, 100), stream.SampleWithSeed(2, 100), stream.Sort().Num(1), stream.WriteLines(os.Stdout), ) // Output: // 11 // 46 }
func BenchmarkWrite(b *testing.B) { f, err := os.Create("/dev/null") if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } stream.Run( stream.Repeat("hello", b.N), stream.WriteLines(f), ) }
func ExampleGrepNot() { stream.Run( stream.Numbers(1, 12), stream.GrepNot("^.$"), stream.WriteLines(os.Stdout), ) // Output: // 10 // 11 // 12 }
func ExampleIf() { stream.Run( stream.Numbers(1, 12), stream.If(func(s string) bool { return len(s) > 1 }), stream.WriteLines(os.Stdout), ) // Output: // 10 // 11 // 12 }
func ExampleNumbers() { stream.Run( stream.Numbers(2, 5), stream.WriteLines(os.Stdout), ) // Output: // 2 // 3 // 4 // 5 }
func ExampleXargsFilter_LimitArgs() { stream.Run( stream.Numbers(1, 5), stream.Xargs("echo").LimitArgs(2), stream.WriteLines(os.Stdout), ) // Output: // 1 2 // 3 4 // 5 }
func ExampleSort() { stream.Run( stream.Items("banana", "apple", "cheese", "apple"), stream.Sort(), stream.WriteLines(os.Stdout), ) // Output: // apple // apple // banana // cheese }
func ExampleXargs_splitArguments() { // Xargs should split the long list of arguments into // three executions to keep command length below 4096. stream.Run( stream.Numbers(1, 2000), stream.Xargs("echo"), stream.Command("wc", "-l"), stream.WriteLines(os.Stdout), ) // Output: // 3 }
func ExampleReadLines() { stream.Run( stream.ReadLines(bytes.NewBufferString("the\nquick\nbrown\nfox\n")), stream.Sort(), stream.WriteLines(os.Stdout), ) // Output: // brown // fox // quick // the }
func ExampleCommand_outputOnly() { stream.Run( stream.Command("find", ".", "-type", "f", "-print"), stream.Grep(`^\./stream.*\.go$`), stream.Sort(), stream.WriteLines(os.Stdout), ) // Output: // ./stream.go // ./stream_test.go }