Hello. Is there a plan to add some functions from ...
# language-proposals
c
Hello. Is there a plan to add some functions from java Optional to nullable kotlin type ? I mainly think about : filter and map (ifPresent could be interesting too). I know that these methods can be implemented with the let function but the name of this method is not very intuitive (I think) and does not reflect the goal of what we want to do. Consider the following example (in java) :
Copy code
Optional<String> optionalString = getSomeString();
return optionalString
.map(String::length)
.filter(length -> length <= 10);
Now in Kotlin :
Copy code
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 :
Copy code
val nullableString: String? = getSomeString();
return nullableString
.mapTo { it.length }
.filterBy { it <= 10 }
No need of ?. and clear objective of every step.