예제 #1
0
func ExampleColumns() {
	stream.Run(
		stream.Items("hello world"),
		stream.Columns(2, 3, 1),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// world hello
}
예제 #2
0
func ExampleItems() {
	stream.Run(
		stream.Items("hello", "world"),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// hello
	// world
}
예제 #3
0
func ExampleNumberLines() {
	stream.Run(
		stream.Items("a", "b"),
		stream.NumberLines(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	//     1 a
	//     2 b
}
예제 #4
0
func ExampleReverse() {
	stream.Run(
		stream.Items("a", "b"),
		stream.Reverse(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// b
	// a
}
예제 #5
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>
}
예제 #6
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
}
예제 #7
0
func ExampleUniqWithCount() {
	stream.Run(
		stream.Items("a", "b", "b", "c"),
		stream.UniqWithCount(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1 a
	// 2 b
	// 1 c
}
예제 #8
0
func ExampleSort() {
	stream.Run(
		stream.Items("banana", "apple", "cheese", "apple"),
		stream.Sort(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// apple
	// apple
	// banana
	// cheese
}
예제 #9
0
func ExampleUniq() {
	stream.Run(
		stream.Items("a", "b", "b", "c", "b"),
		stream.Uniq(),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// a
	// b
	// c
	// b
}
예제 #10
0
func ExampleMap() {
	stream.Run(
		stream.Items("hello", "there", "how", "are", "you?"),
		stream.Map(func(s string) string {
			return fmt.Sprintf("%d %s", len(s), s)
		}),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 5 hello
	// 5 there
	// 3 how
	// 3 are
	// 4 you?
}
예제 #11
0
func ExampleSorter_TextDecreasing() {
	stream.Run(
		stream.Items(
			"10 bananas",
			"20 apples",
			"30", // Will sort first since column 2 is missing
		),
		stream.Sort().TextDecreasing(2),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 10 bananas
	// 20 apples
	// 30
}
예제 #12
0
func ExampleSorter_NumDecreasing() {
	stream.Run(
		stream.Items(
			"a 100",
			"b 20",
			"c notanumber",
			"d",
		),
		stream.Sort().NumDecreasing(2),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// c notanumber
	// a 100
	// b 20
	// d
}
예제 #13
0
func ExampleSorter_Num() {
	stream.Run(
		stream.Items(
			"a 100",
			"b 20.3",
			"c notanumber", // Will sort last since column 2 is not a number
			"d",            // Will sort earliest since column 2 is missing
		),
		stream.Sort().Num(2),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// d
	// b 20.3
	// a 100
	// c notanumber
}
예제 #14
0
func ExampleSort_multipleColumns() {
	// Sort numerically by column 1. Break ties by sorting
	// lexicographically by column 2.
	stream.Run(
		stream.Items(
			"1970 march",
			"1970 feb",
			"1950 june",
			"1980 sep",
		),
		stream.Sort().Num(1).Text(2),
		stream.WriteLines(os.Stdout),
	)
	// Output:
	// 1950 june
	// 1970 feb
	// 1970 march
	// 1980 sep
}