Luke
03/01/2023, 9:31 PMval String.isValidUrl: Boolean get() = TODO()
fun areValidCredentials(email: String, password: String): Boolean = TODO()
Then, could the compiler generate:
val String.isNotValidUrl: Boolean inline get() = !isValidUrl
fun areNotValidCredentials(email: String, password: String): Boolean = !areValidCredentials(email, password)
The name could be changed via annotation, or by default the compiler wouldn't do anything but adding an annotation with an optional name could generate the negations..?
I feel it would make code more readable than having the !
before or .not()
after. The standard library already has some negated function such as List.isNotEmpty, so I feel Kotlin could improve by generalizing this trend.ephemient
03/01/2023, 9:36 PMdmitriy.novozhilov
03/01/2023, 9:37 PMLuke
03/01/2023, 9:51 PMCasey Brooks
03/01/2023, 10:07 PMelizarov
03/02/2023, 4:17 PMLuke
03/02/2023, 9:44 PM!
operator would be far from the function, and .not()
is not as readable as having isNotEmpty()
for example, or isInvalid
vs isValid.not()
. But that's just my opinionelizarov
03/03/2023, 8:14 AMsomeChainOfCalls.!isEmpty()
which reads very much like someChainOfCalls.isNotEmpty()
without having to have a separate isNotXxx
version for every isXxx
function.ilya.gorbunov
03/03/2023, 10:05 PMelizarov
03/04/2023, 1:41 PM