func ExampleColumns() { stream.Run( stream.Items("hello world"), stream.Columns(2, 3, 1), stream.WriteLines(os.Stdout), ) // Output: // world hello }
func ExampleItems() { stream.Run( stream.Items("hello", "world"), stream.WriteLines(os.Stdout), ) // Output: // hello // world }
func ExampleNumberLines() { stream.Run( stream.Items("a", "b"), stream.NumberLines(), stream.WriteLines(os.Stdout), ) // Output: // 1 a // 2 b }
func ExampleReverse() { stream.Run( stream.Items("a", "b"), stream.Reverse(), stream.WriteLines(os.Stdout), ) // Output: // b // a }
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 ExampleUniqWithCount() { stream.Run( stream.Items("a", "b", "b", "c"), stream.UniqWithCount(), stream.WriteLines(os.Stdout), ) // Output: // 1 a // 2 b // 1 c }
func ExampleSort() { stream.Run( stream.Items("banana", "apple", "cheese", "apple"), stream.Sort(), stream.WriteLines(os.Stdout), ) // Output: // apple // apple // banana // cheese }
func ExampleUniq() { stream.Run( stream.Items("a", "b", "b", "c", "b"), stream.Uniq(), stream.WriteLines(os.Stdout), ) // Output: // a // b // c // b }
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? }
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 }
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 }
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 }
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 }