Skip to content

Instantly share code, notes, and snippets.

View Rasalexman's full-sized avatar
🌍
i hope you are going to have an amazing day

Alexandr Minkin Rasalexman

🌍
i hope you are going to have an amazing day
View GitHub Profile
typealias UserAddressBuilderLambda = () -> UserAddress // 1
class UserAddressBuilder(
addressInit: UserAddressBuilder.() -> Unit // 2
) : UserAddressBuilderLambda {
init {
this.addressInit() // 3
}
var userCity: String = ""
var userCountry: String = ""
typealias UserAddressBuilderLambda = () -> UserAddress // 1
class UserAddressBuilder(
addressInit: UserAddressBuilder.() -> Unit // 2
) : () -> UserAddress {
init {
this.addressInit() // 3
}
var userCity: String = ""
var userCountry: String = ""
inline fun <reified T : User> UserBuilder.build(): T {
return when (T::class) { // 1
UserImp::class -> { // 2
UserImp(
address = userAddress,
id = userId,
name = userName
) as T
}
else -> object : User { // 3
class UserBuilder {
var userId: String = ""
var userName: String = ""
var userAddress: UserAddress = object : UserAddress {
override val city: String = ""
override val country: String = ""
}
fun userAddress(userAddressInit: UserAddressBuilder.() -> Unit) {
userAddress = UserAddressBuilder(userAddressInit).invoke()
}
inline fun <reified T : User> user(noinline creator: UserBuilder.() -> Unit): T {
return initClass(UserBuilder(), creator).build()
}
inline fun <T, R> initClass(tag: T, init: T.() -> R): T {
tag.init()
return tag
}
interface User {
val name: String
val id: String
val address: UserAddress
}
interface UserAddress {
val city: String
val country: String
}
fun <T> T.call(action: T.() -> Unit): T {
this.action()
return this
}
class SingleClass(val name: String) {
fun callSimpleFunction() = println("----> Single name is $name")
fun callFuncWithInput(input: String) = println("----> Single input = $input")
}
typealias SingleLiteral = SingleClass.(String) -> Unit
fun main(args: Array<String>) {
val singleLiteral: SingleLiteral = { inputString ->
this.callSimpleFunction()
this.callFuncWithInput(inputString)
}
class AccountDelegate(
presenter: IAccountContract.IPresenter
) : BaseDelegate<IAccountContract.IView, IAccountContract.IPresenter>(presenter),
IAccountContract.IDelegate {
// 1
override fun delegate() {
println("Account delegate is ready to work")
// 2
with(view as AccountFragment) {
// 3
class MainApplication : Application(), KodeinAware {
override val kodein: Kodein by Kodein.lazy {
bind<HomePresenter>() with singleton { HomePresenter() }
bind<AccountPresenter>() with singleton { AccountPresenter() }
bind<AccountDelegate>() with provider { AccountDelegate(instance()) }
bind<HomeDelegate>() with provider { HomeDelegate(instance()) }
}
}