mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-11 16:22:26 +08:00
Add ToPointer,ToSlicePointer,ToSlice func (#36)
* Add ToPointer func * Add ToSlice and ToSlicePointer func Co-authored-by: zhanghu <305835360@qq.com>
This commit is contained in:
@@ -803,3 +803,21 @@ func LastIndexOf[T any](slice []T, value T) int {
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
// ToSlicePointer returns a pointer to the slices of a variable parameter transformation
|
||||
func ToSlicePointer[T any](value ...T) []*T {
|
||||
out := make([]*T, len(value))
|
||||
for i := range value {
|
||||
out[i] = &value[i]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ToSlice returns a slices of a variable parameter transformation
|
||||
func ToSlice[T any](value ...T) []T {
|
||||
out := make([]T, len(value))
|
||||
for i := range value {
|
||||
out[i] = value[i]
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user