Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Created December 15, 2018 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivancorrales/4e9e05d902538bddcadc7c2297bcf1c6 to your computer and use it in GitHub Desktop.
Save ivancorrales/4e9e05d902538bddcadc7c2297bcf1c6 to your computer and use it in GitHub Desktop.
stream.Count / stream.IndexOf / stream.LastIndexOf / stream.Contains
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