Skip to content

Commit 5b72292

Browse files
committed
Update README with predicate possibilities for Contains, IndexOf & LastIndexOf functions
1 parent 193afc3 commit 5b72292

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ this can be replaced by ``funk.Contains``:
109109
110110
// slice of Foo ptr
111111
funk.Contains([]*Foo{f}, f) // true
112+
funk.Contains([]*Foo{f}, func (foo *Foo) bool {
113+
return foo.ID == f.ID
114+
}) // true
112115
funk.Contains([]*Foo{f}, nil) // false
113116
114117
b := &Foo{
@@ -126,6 +129,9 @@ this can be replaced by ``funk.Contains``:
126129
127130
// even map
128131
funk.Contains(map[int]string{1: "Florent"}, 1) // true
132+
funk.Contains(map[int]string{1: "Florent"}, func(key int, name string) bool {
133+
return key == 1 // or `name == "Florent"` for the value type
134+
}) // true
129135
130136
see also, typesafe implementations: ContainsInt_, ContainsInt64_, ContainsFloat32_, ContainsFloat64_, ContainsString_
131137

@@ -175,6 +181,9 @@ if the value cannot be found.
175181
176182
// slice of string
177183
funk.IndexOf([]string{"foo", "bar"}, "bar") // 1
184+
funk.IndexOf([]string{"foo", "bar"}, func(value string) bool {
185+
return value == "bar"
186+
}) // 1
178187
funk.IndexOf([]string{"foo", "bar"}, "gilles") // -1
179188
180189
see also, typesafe implementations: IndexOfInt_, IndexOfInt64_, IndexOfFloat32_, IndexOfFloat64_, IndexOfString_
@@ -195,6 +204,9 @@ if the value cannot be found.
195204
196205
// slice of string
197206
funk.LastIndexOf([]string{"foo", "bar", "bar"}, "bar") // 2
207+
funk.LastIndexOf([]string{"foo", "bar"}, func(value string) bool {
208+
return value == "bar"
209+
}) // 2
198210
funk.LastIndexOf([]string{"foo", "bar"}, "gilles") // -1
199211
200212
see also, typesafe implementations: LastIndexOfInt_, LastIndexOfInt64_, LastIndexOfFloat32_, LastIndexOfFloat64_, LastIndexOfString_

0 commit comments

Comments
 (0)