ctardella
12/22/2016, 9:12 AMOptional<String> optionalString = getSomeString();
return optionalString
.map(String::length)
.filter(length -> length <= 10);
Now in Kotlin :
val nullableString: String? = getSomeString();
return nullableString
?.let { it.length }
?.let { if(it <= 10) it else null }
In kotlin we use ?.let for both mapping and filtering (I didn't find another way to do that for nullable type)
It would be better if I could write :
val nullableString: String? = getSomeString();
return nullableString
.mapTo { it.length }
.filterBy { it <= 10 }
No need of ?. and clear objective of every step.