我想将动态keySelector
传递给我的groupingBy
函数。这可能吗?
private fun hasNumberOfIdenticalValues(hand: ArrayList<Card>, values: ArrayList<String>, limit: Int) : Boolean {
var numberOfOccurrences : Map<String, Int> = hashMapOf()
for(value in values) {
numberOfOccurrences = hand.groupingBy{it.suit}.eachCount()
}
return true
}
答案 0 :(得分:0)
您可以,您只需要返回将对交互进行分类的字符串。例如,按西装颜色分开卡片:
fun Card.color(): String {
return if(listof("diamonds","hearts").contains(this.suit))
"red"
else
"black"
}
for(value in values) {
numberOfOccurrences = hand.groupingBy{it.color()}.eachCount()
}