mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-14 17:52:28 +08:00
feat:(slice add AppendIfAbsent function) (#52)
Co-authored-by: george.zheng <george.zheng@ambergroup.io>
This commit is contained in:
@@ -851,3 +851,11 @@ func ToSlice[T any](value ...T) []T {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// AppendIfAbsent only absent append the value
|
||||
func AppendIfAbsent[T comparable](slices []T, value T) []T {
|
||||
if !Contain(slices, value) {
|
||||
slices = append(slices, value)
|
||||
}
|
||||
return slices
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user