cedric
11/19/2017, 6:58 PMdanielspeixoto
11/19/2017, 9:11 PMShawn
11/19/2017, 9:16 PMShawn
11/19/2017, 9:16 PMdanielspeixoto
11/19/2017, 9:16 PMdave08
11/19/2017, 9:29 PMnfrankel
11/20/2017, 9:49 PM.?
operator
but for collections which are/are not empty
any hint?ebonet
11/20/2017, 9:50 PMkevinmost
11/20/2017, 9:51 PMlist.takeIf { it.isNotEmpty }
kevinmost
11/20/2017, 9:51 PMkevinmost
11/20/2017, 9:51 PMlist.takeUnless { it.isEmpty }
nfrankel
11/20/2017, 9:51 PMreturn when (response.resultsCount) {
0 -> "No match found, try again"
else -> {
val speechRecognitionResult = response.resultsList[0]
when (speechRecognitionResult.alternativesCount) {
0 -> "No match found, try again"
else -> speechRecognitionResult.alternativesList[0].transcript
}
}
}
nfrankel
11/20/2017, 9:51 PMebonet
11/20/2017, 9:52 PMebonet
11/20/2017, 9:52 PMif (response.resultsCount == 0) return "No match found, try again"
val speechRecognitionResult = response.resultsList[0];
if( speechRecognitionResult.alternativesCount == 0) return "No match found, try again";
return speechRecognitionResult.alternativesList[0].transcript;
ebonet
11/20/2017, 9:55 PMebonet
11/20/2017, 9:56 PMif (response.resultsCount == 0 || response.resultsList[0].alternativesCount == 0) return “No match found, try again”;
return response.resultsList[0].alternativesList[0].transcript
nfrankel
11/20/2017, 9:57 PMnfrankel
11/20/2017, 9:57 PMebonet
11/20/2017, 9:58 PMebonet
11/20/2017, 9:59 PMnfrankel
11/20/2017, 10:00 PMebonet
11/20/2017, 10:01 PMebonet
11/20/2017, 10:02 PMif (response.isEmpty() || response.resultsList[0].isEmpty()) return "No match found, try again";
return response.resultsList[0].alternativesList[0].transcript
Shawn
11/20/2017, 10:02 PMwhen
to replicate what’s essentially a chained comparison isn’t idiomatic my dudepavel
11/20/2017, 10:03 PMebonet
11/20/2017, 10:05 PMreturn response.resultsList.firstOrNull()?.altenartiveList?.firstOrNull()?.transcript ?: "No match found, try again"
ebonet
11/20/2017, 10:06 PMebonet
11/20/2017, 10:06 PMShawn
11/20/2017, 10:06 PM