Marko Novakovic
1 min readMar 31, 2021

--

Great article. I knew of some use-cases presented here but sadly never used them in real world :/.

One question. I've looked into Values4k you linked at the end and saw that `Validation`, for example, there is just `typealias`.

Now am wondering what is the difference between:

```

fun interface Validation : (String) -> Boolean {

companion object

}

val Validation.Companion.validateEmail

get() = Validation { it.isNotEmpty() }

val Validation.Companion.validatePassword

get() = Validation { it.isNotEmpty() }

val isFormValid = Validation.validateEmail("email") && Validation.validatePassword("password")

```

and

```

typealias Validation = (String) -> Boolean

val validateEmail: Validation = { email: String -> email.isNotEmpty() }

val validatePassword: Validation = { password: String -> password.isNotEmpty() }

val isFormValid = validateEmail("email") && validatePassword("password")

```

I understand that this example is not the best because it's really simple and you used it to showcase feature and not necessarily as an "do it like this" example so it can be confusing. BUT I just struggle to come up with more complex example where `interface` approach would add value and make more sense.

I also understand that in `interface` example we create TYPE but is it the same as `typealias` one? `typealias` does the same right? You can still create extensions for it, extend it etc.

I quess that my question really is when would `interface` example make more sense than `typealias` one?

--

--

Responses (1)