Exemple #1
0
func ExampleCommand_withError() {
	err := stream.Run(stream.Command("no_such_command"))
	if err == nil {
		fmt.Println("execution of missing command succeeded unexpectedly")
	}
	// Output:
}
Exemple #2
0
func ExampleFind_error() {
	err := stream.Run(stream.Find("/no_such_dir"))
	if err == nil {
		fmt.Println("stream.Find did not return expected error")
	}
	// Output:
}
Exemple #3
0
func ExampleSample() {
	stream.Run(
		stream.Numbers(100, 200),
		stream.Sample(4),
		stream.WriteLines(os.Stdout),
	)
	// Output not checked since it is non-deterministic.
}
Exemple #4
0
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)
}
Exemple #5
0
func ExampleXargs() {
	stream.Run(
		stream.Numbers(1, 5),
		stream.Xargs("echo"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1 2 3 4 5
}
Exemple #6
0
func ExampleItems() {
	stream.Run(
		stream.Items("hello", "world"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// hello
	// world
}
Exemple #7
0
func ExampleCommand() {
	stream.Run(
		stream.Numbers(1, 100),
		stream.Command("wc", "-l"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 100
}
Exemple #8
0
func ExampleCat() {
	stream.Run(
		stream.Cat("stream_test.go"),
		stream.Grep("^func ExampleCat"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// func ExampleCat() {
}
Exemple #9
0
func ExampleColumns() {
	stream.Run(
		stream.Items("hello world"),
		stream.Columns(2, 3, 1),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// world hello
}
Exemple #10
0
func ExampleNumberLines() {
	stream.Run(
		stream.Items("a", "b"),
		stream.NumberLines(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	//     1 a
	//     2 b
}
Exemple #11
0
func ExampleWriteLines() {
	stream.Run(
		stream.Numbers(1, 3),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1
	// 2
	// 3
}
Exemple #12
0
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
}
Exemple #13
0
func ExampleFind() {
	stream.Run(
		stream.Find(".").IfMode(os.FileMode.IsRegular),
		stream.Grep("stream"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// stream.go
	// stream_test.go
}
Exemple #14
0
func ExampleDropFirst() {
	stream.Run(
		stream.Numbers(1, 10),
		stream.DropFirst(8),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 9
	// 10
}
Exemple #15
0
func ExampleLast() {
	stream.Run(
		stream.Numbers(1, 10),
		stream.Last(2),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 9
	// 10
}
Exemple #16
0
func ExampleReverse() {
	stream.Run(
		stream.Items("a", "b"),
		stream.Reverse(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// b
	// a
}
Exemple #17
0
func ExampleUniqWithCount() {
	stream.Run(
		stream.Items("a", "b", "b", "c"),
		stream.UniqWithCount(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1 a
	// 2 b
	// 1 c
}
Exemple #18
0
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>
}
Exemple #19
0
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
}
Exemple #20
0
func ExampleFirst() {
	stream.Run(
		stream.Numbers(1, 10),
		stream.First(3),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1
	// 2
	// 3
}
Exemple #21
0
func ExampleSampleWithSeed() {
	stream.Run(
		stream.Numbers(1, 100),
		stream.SampleWithSeed(2, 100),
		stream.Sort().Num(1),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 11
	// 46
}
Exemple #22
0
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),
	)
}
Exemple #23
0
func ExampleGrepNot() {
	stream.Run(
		stream.Numbers(1, 12),
		stream.GrepNot("^.$"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 10
	// 11
	// 12
}
Exemple #24
0
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
}
Exemple #25
0
func ExampleNumbers() {
	stream.Run(
		stream.Numbers(2, 5),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 2
	// 3
	// 4
	// 5
}
Exemple #26
0
func ExampleXargsFilter_LimitArgs() {
	stream.Run(
		stream.Numbers(1, 5),
		stream.Xargs("echo").LimitArgs(2),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1 2
	// 3 4
	// 5
}
Exemple #27
0
func ExampleSort() {
	stream.Run(
		stream.Items("banana", "apple", "cheese", "apple"),
		stream.Sort(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// apple
	// apple
	// banana
	// cheese
}
Exemple #28
0
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
}
Exemple #29
0
func ExampleReadLines() {
	stream.Run(
		stream.ReadLines(bytes.NewBufferString("the\nquick\nbrown\nfox\n")),
		stream.Sort(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// brown
	// fox
	// quick
	// the
}
Exemple #30
0
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
}