Esempio n. 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:
}
Esempio n. 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:
}
Esempio n. 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.
}
Esempio n. 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)
}
Esempio n. 5
0
func ExampleXargs() {
	stream.Run(
		stream.Numbers(1, 5),
		stream.Xargs("echo"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1 2 3 4 5
}
Esempio n. 6
0
func ExampleItems() {
	stream.Run(
		stream.Items("hello", "world"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// hello
	// world
}
Esempio n. 7
0
func ExampleCommand() {
	stream.Run(
		stream.Numbers(1, 100),
		stream.Command("wc", "-l"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 100
}
Esempio n. 8
0
func ExampleCat() {
	stream.Run(
		stream.Cat("stream_test.go"),
		stream.Grep("^func ExampleCat"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// func ExampleCat() {
}
Esempio n. 9
0
func ExampleColumns() {
	stream.Run(
		stream.Items("hello world"),
		stream.Columns(2, 3, 1),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// world hello
}
Esempio n. 10
0
func ExampleNumberLines() {
	stream.Run(
		stream.Items("a", "b"),
		stream.NumberLines(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	//     1 a
	//     2 b
}
Esempio n. 11
0
func ExampleWriteLines() {
	stream.Run(
		stream.Numbers(1, 3),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1
	// 2
	// 3
}
Esempio n. 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
}
Esempio n. 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
}
Esempio n. 14
0
func ExampleDropFirst() {
	stream.Run(
		stream.Numbers(1, 10),
		stream.DropFirst(8),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 9
	// 10
}
Esempio n. 15
0
func ExampleLast() {
	stream.Run(
		stream.Numbers(1, 10),
		stream.Last(2),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 9
	// 10
}
Esempio n. 16
0
func ExampleReverse() {
	stream.Run(
		stream.Items("a", "b"),
		stream.Reverse(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// b
	// a
}
Esempio n. 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
}
Esempio n. 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>
}
Esempio n. 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
}
Esempio n. 20
0
func ExampleFirst() {
	stream.Run(
		stream.Numbers(1, 10),
		stream.First(3),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1
	// 2
	// 3
}
Esempio n. 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
}
Esempio n. 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),
	)
}
Esempio n. 23
0
func ExampleGrepNot() {
	stream.Run(
		stream.Numbers(1, 12),
		stream.GrepNot("^.$"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 10
	// 11
	// 12
}
Esempio n. 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
}
Esempio n. 25
0
func ExampleNumbers() {
	stream.Run(
		stream.Numbers(2, 5),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 2
	// 3
	// 4
	// 5
}
Esempio n. 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
}
Esempio n. 27
0
func ExampleSort() {
	stream.Run(
		stream.Items("banana", "apple", "cheese", "apple"),
		stream.Sort(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// apple
	// apple
	// banana
	// cheese
}
Esempio n. 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
}
Esempio n. 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
}
Esempio n. 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
}