Hexa
10/04/2018, 7:46 PMasSquence
before calling groupBy
on this function that I wrote, but I can't find any evidence to prove if this is a good idea or not. I wonder if anyone here can suggest if this is a good idea. So basically here is what the code look like //BEFORE adding.asSequence()
override fun handle(event: List<String>): Either<Errors.RequestError, Pair<List<Errors.RequestError>, Int>> =
emailParser.parseEmails(event)
.map {
Pair(
first = it.first,
second = it.second
.groupBy { it.emailAdrress }
.map {
Pair(
first = MessageDestination(it.key),
second = it.value.map {
MessageSender(
message = it.environment
)
}
)
}.toMap()
)
}.flatMap { pair ->
service.handleRequests(pair.second)
.map {
Pair(pair.first, pair.second.size)
}
}
//AFTER adding .asSequence()
override fun handle(event: List<String>): Either<Errors.RequestError, Pair<List<Errors.RequestError>, Int>> =
emailParser.parseEmails(event)
.map {
Pair(
first = it.first,
second = it.second
.asSequence()
.groupBy { it.emailAdrress }
.map {
Pair(
first = MessageDestination(it.key),
second = it.value.map {
MessageSender(
message = it.environment
)
}
)
}
.toList().toMap()
)
}.flatMap { pair ->
service.handleRequests(pair.second)
.map {
Pair(pair.first, pair.second.size)
}
}
Matheus
10/04/2018, 7:58 PMMatheus
10/04/2018, 7:58 PMShawn
10/04/2018, 8:01 PMShawn
10/04/2018, 8:01 PM.associate { ... }
rather than mapping and then calling .toMap()
on the resulting listShawn
10/04/2018, 8:02 PMShawn
10/04/2018, 8:02 PMHexa
10/04/2018, 8:11 PMHexa
10/04/2018, 8:12 PMShawn
10/04/2018, 8:12 PMShawn
10/04/2018, 8:12 PMDico
10/04/2018, 8:24 PM