-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path07_contains.go
More file actions
53 lines (41 loc) · 1.28 KB
/
07_contains.go
File metadata and controls
53 lines (41 loc) · 1.28 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
// 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 7:
// Metoda Contains().
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
func main() {
values := []int{1, 2, 3, 4, 5}
fmt.Printf("input: %v\n", values)
stream := koazee.StreamOf(values)
p1, _ := stream.Contains(2)
fmt.Printf("contains 2? %v\n", p1)
p2, _ := stream.Contains(42)
fmt.Printf("contains 42? %v\n", p2)
fmt.Println()
words := []string{"one", "two", "three", "four", "five"}
fmt.Printf("words: %v\n", words)
stream = koazee.StreamOf(words)
p3, _ := stream.Contains("one")
fmt.Printf("contains 'one'? %v\n", p3)
p4, e1 := stream.Contains("ten")
fmt.Printf("contains 'ten'? %v\n", p4)
fmt.Printf("error %v\n", e1)
p4, e2 := stream.Contains(42)
fmt.Printf("contains 42? %v\n", p4)
fmt.Printf("error %v\n", e2)
}