gpt4 book ai didi

android - Kotlin 从嵌套的 forEach 返回@forEach

转载 作者:行者123 更新时间:2023-12-02 12:04:06 24 4
gpt4 key购买 nike

我想做一些像 break在嵌套的 forEach 循环中过滤我的 searchView 中的数据(如果数据内容在我的搜索中包含任何单词)。

val filtered = mutableListOf<EventEntity>()

rawDataList.forEach {data ->
text.split(' ').forEach { word ->
if (data.content.contains(word, ignoreCase = true)) {
filtered.add(data)
return@forEach // **There is more than one label with such a name in this scope**
}
}
}

我的情况是否存在优雅的解决方案?

最佳答案

如果您遇到此错误并且无法使用内置函数修复它,您可以通过添加 name@ 将自定义标签应用于 lambdas block 之前:

rawDataList.forEach outer@{data ->
text.split(' ').forEach { word ->
if (data.content.contains(word, ignoreCase = true)) {
filtered.add(data)
return@outer
}
}
}

关于android - Kotlin 从嵌套的 forEach 返回@forEach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58787708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com