Skip to content

Commit dbdc547

Browse files
committed
history: update
1 parent 05815f5 commit dbdc547

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
File renamed without changes.

history/202008.go2.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2020 Changkun Ou. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package history
6+
7+
// type parameters
8+
9+
type Ordered interface {
10+
type int, int8, int16, int32, int64,
11+
uint, uint8, uint16, uint32, uint64, uintptr,
12+
float32, float64,
13+
string
14+
}
15+
16+
// Max returns the maximum among all parameters
17+
func Max[type T Ordered](v0 T, vn ...T) T {
18+
switch l := len(vn); {
19+
case l == 0:
20+
return v0
21+
case l == 1:
22+
if v0 > vn[0] { return v0 }
23+
return vn[0]
24+
default:
25+
vv := Max(vn[0], vn[1:]...)
26+
if v0 > vv { return v0 }
27+
return vv
28+
}
29+
}
30+
31+
// a more complex example:
32+
33+
type I1 [type P1] interface {
34+
m1(x P1)
35+
}
36+
type I2 [type P1, P2] interface {
37+
m2(x P1) P2
38+
type int, float64
39+
}
40+
41+
func F[type P1 I1[P1], P2 I2[P1, P2]] (x P1, y P2) {}

0 commit comments

Comments
 (0)