-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: slice 包新增 Zoom 函数, stream 包支持 Zoom 函数
- Loading branch information
1 parent
d72f185
commit 62ef35a
Showing
2 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package slice | ||
|
||
// Zoom 将切片的长度缩放到指定的大小,如果 newSize 小于 slice 的长度,则会截断 slice,如果 newSize 大于 slice 的长度,则会在 slice 的末尾添加零值数据 | ||
func Zoom[V any](newSize int, slice []V) []V { | ||
if newSize < 0 { | ||
newSize = 0 | ||
} | ||
var s = make([]V, newSize) | ||
copy(s, slice) | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters