Dynamic groupingBy keyselector in Kotlin
up vote
0
down vote
favorite
I would like to pass a dynamic keySelector
to my groupingBy
function. Is this possible?
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
}
java kotlin
add a comment |
up vote
0
down vote
favorite
I would like to pass a dynamic keySelector
to my groupingBy
function. Is this possible?
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
}
java kotlin
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I would like to pass a dynamic keySelector
to my groupingBy
function. Is this possible?
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
}
java kotlin
I would like to pass a dynamic keySelector
to my groupingBy
function. Is this possible?
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
}
java kotlin
java kotlin
asked Nov 10 at 19:28
Paul Mcloughlin
1,2782917
1,2782917
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can, you just need to return the string that will classify the interation. For instance, to separete the cards by color of the suit:
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()
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can, you just need to return the string that will classify the interation. For instance, to separete the cards by color of the suit:
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()
}
add a comment |
up vote
0
down vote
You can, you just need to return the string that will classify the interation. For instance, to separete the cards by color of the suit:
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()
}
add a comment |
up vote
0
down vote
up vote
0
down vote
You can, you just need to return the string that will classify the interation. For instance, to separete the cards by color of the suit:
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()
}
You can, you just need to return the string that will classify the interation. For instance, to separete the cards by color of the suit:
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()
}
answered Nov 10 at 20:08
Raphael
1,30511020
1,30511020
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242646%2fdynamic-groupingby-keyselector-in-kotlin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown