We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func RemoveString(slice []string, str string) []string { result := make([]string, 0, len(slice)) for _, item := range slice { if item != str { result = append(result, item) } } return result }
The text was updated successfully, but these errors were encountered:
@J4sonZ , 使用slice.Filter实现。
Sorry, something went wrong.
@J4sonZ , 使用slice.Filter实现。 @duke-git
感觉上是没问题的,我只是提个建议哈, RemoveString(slice []string, str string) []string 这个功能常用级别应该非常 top,如果是 slice.Filter,每次使用的时候带一个函数在参数中感觉不够简洁。有一个库 goutils,把这个功能单独抽出来
@J4sonZ RemoveString不是通用函数。如果要实现RemoveString,还需实现RemoveInt, RemoveFloat64, RemoveXXX. 实现泛型版本:RemoveT[T comparable](slice []T, item T) []T. 这个T还要求是comparable的,且实现都要调用slice.Filter,会产生大量浅函数。如果需要大量调用RemoveString,可以在项目内部封装实现。
No branches or pull requests
func RemoveString(slice []string, str string) []string {
result := make([]string, 0, len(slice))
for _, item := range slice {
if item != str {
result = append(result, item)
}
}
return result
}
The text was updated successfully, but these errors were encountered: