So I have this definition:
sealed interface ParseResult<out R> {
data class Success<R>(val value: R) : ParseResult<R>
data class Failure(val original: String, val error: Throwable) : ParseResult<Nothing>
}
I want to wrap certain elements in a Success. And I know I can do it like this...
list.map{ParseResult.Success(it)}
But is there a way to use a constructor reference?
list.map(ParseResult::Success) //this won't compile
You can use a constructor reference if you add an
import
:Or even a typealias:
Then you can do:
The idea here is to make
ParseResult.Success
referrable by a simple name.Not being able to do
ParseResult::Success
does look like a bug to me though. Compare: