-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path08_index_of.go
More file actions
61 lines (46 loc) · 1.45 KB
/
08_index_of.go
File metadata and controls
61 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Dvacátá osmá část
// Datové struktury s líným vyhodnocováním v programovacím jazyce Go
// https://www.root.cz/clanky/datove-struktury-s-linym-vyhodnocovanim-v-programovacim-jazyce-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z dvacáté osmé části:
// https://github.com/tisnik/go-root/blob/master/article_28/README.md
//
// Demonstrační příklad číslo 8:
// Metoda IndexOf().
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
func main() {
values := []int{1, 2, 3, 4, 5, 1}
fmt.Printf("input: %v\n", values)
stream := koazee.StreamOf(values)
i1, _ := stream.IndexOf(1)
fmt.Printf("index of 1: %v\n", i1)
i2, _ := stream.LastIndexOf(1)
fmt.Printf("last index of 1: %v\n", i2)
i3, _ := stream.IndexOf(42)
fmt.Printf("index of 42: %v\n", i3)
fmt.Println()
words := []string{"one", "two", "three", "four", "five"}
fmt.Printf("words: %v\n", words)
stream = koazee.StreamOf(words)
i4, _ := stream.IndexOf("one")
fmt.Printf("index of 'one': %v\n", i4)
i5, _ := stream.LastIndexOf("two")
fmt.Printf("last index of 'one': %v\n", i5)
i6, e6 := stream.IndexOf("foobar")
fmt.Printf("index of 'foobar': %v\n", i6)
fmt.Printf("error: %v\n", e6)
fmt.Println()
i7, e7 := stream.IndexOf(42)
fmt.Printf("index of 42: %v\n", i7)
fmt.Printf("error: %v\n", e7)
}