github.com/hedzr/evendeep@v0.4.8/internal/tool/tool_go118.gobak (about)

     1  //go:build go1.18
     2  // +build go1.18
     3  
     4  package tool
     5  
     6  // Min _
     7  func Min[T any](a, b T) T {
     8  	if a < b {
     9  		return a
    10  	}
    11  	return b
    12  }
    13  
    14  // Max _
    15  func Max[T any](a, b T) T {
    16  	if a > b {
    17  		return a
    18  	}
    19  	return b
    20  }
    21  
    22  // ReverseSlice _
    23  func ReverseSlice[T any](s []T) {
    24  	n := len(s)
    25  	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
    26  		s[i], s[j] = s[j], s[i]
    27  	}
    28  }
    29  
    30  // ReverseStringSlice reverse a string slice
    31  func ReverseStringSlice(s []string) []string {
    32  	ReverseSlice(s)
    33  	return s
    34  
    35  	// // reverse it
    36  	// i := 0
    37  	// j := len(a) - 1
    38  	// for i < j {
    39  	// 	a[i], a[j] = a[j], a[i]
    40  	// 	i++
    41  	// 	j--
    42  	// }
    43  }