Skip to content

Commit

Permalink
_content: change generic min example to index
Browse files Browse the repository at this point in the history
This avoids importing the constraints package, which is no longer in
the standard library.

For golang/go#50792

Change-Id: I0e0f48d414e87418a1fe95e500bb7629127007cc
Reviewed-on: https://go-review.googlesource.com/c/website/+/383254
Reviewed-by: Eli Bendersky‎ <[email protected]>
Reviewed-by: Eli Bendersky <[email protected]>
Trust: DO NOT USE <[email protected]>
Run-TryBot: DO NOT USE <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
ianlancetaylor authored and DO NOT USE committed Feb 8, 2022
1 parent b7142a0 commit 3547304
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
22 changes: 22 additions & 0 deletions _content/doc/play/index-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"
)

// The index function returns the index of the first occurrence of v in s,
// or -1 if not present.
func index[E comparable](s []E, v E) int {
for i, vs := range s {
if v == vs {
return i
}
}
return -1
}

func main() {
s := []int{1, 3, 5, 2, 4}
fmt.Println(index(s, 3))
fmt.Println(index(s, 6))
}
18 changes: 0 additions & 18 deletions _content/doc/play/min-dev.txt

This file was deleted.

2 changes: 1 addition & 1 deletion _content/play.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<option value="multi.txt">Multiple Files</option>
<option value="sleep.go">Sleep</option>
<option value="test.go">Test Function</option>
<option value="min-dev.txt">Generic min</option>
<option value="index-dev.txt">Generic index</option>
</select>
</div>
</div>
Expand Down

0 comments on commit 3547304

Please sign in to comment.