Created
December 15, 2018 08:51
-
-
Save ivancorrales/4e9e05d902538bddcadc7c2297bcf1c6 to your computer and use it in GitHub Desktop.
stream.Count / stream.IndexOf / stream.LastIndexOf / stream.Contains
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/wesovilabs/koazee" | |
) | |
var numbers = []int{1, 5, 4, 3, 2, 7, 1, 8, 2, 3} | |
func main() { | |
fmt.Printf("input: %v\n", numbers) | |
stream := koazee.StreamOf(numbers) | |
count, _ := stream.Count() | |
fmt.Printf("stream.Count(): %d\n", count) | |
index, _ := stream.IndexOf(2) | |
fmt.Printf("stream.IndexOf(2): %d\n", index) | |
index, _ = stream.LastIndexOf(2) | |
fmt.Printf("stream.LastIndexOf(2): %d\n", index) | |
contains, _ := stream.Contains(7) | |
fmt.Printf("stream.Contains(7): %v\n", contains) | |
} | |
/** | |
go run main.go | |
input: [1 5 4 3 2 7 1 8 2 3] | |
stream.Count(): 10 | |
stream.IndexOf(2): 4 | |
stream.LastIndexOf(2): 8 | |
stream.Contains(7): true | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment