This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun someFunction( | |
lambda: (String) -> Unit | |
) { | |
// TODO | |
} | |
fun main() { | |
someFunction({ print(it) }) | |
someFunction { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A.() -> Unit // função que não recebe parâmetros e não tem retorno, no contexto de uma instância de A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(String) -> Int // recebe uma String como parâmetro e retorna um Int | |
() -> Unit // não recebe parâmetro e não retorna nada |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val user = user { | |
name("Fulano") | |
contactInfo { | |
email("fulano@gmail.com") | |
phoneNumber("11991234567") | |
} | |
+Role.User | |
+Role.Admin | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@UserDslScope | |
class UserDsl { | |
... | |
@UserDslScope | |
class UserContactInfoDsl { | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val user = user { | |
name = "Fulano" | |
contactInfo { | |
email = "fulano@gmail.com" | |
phoneNumber = "11991234567" | |
roles { | |
+Role.User | |
+Role.Admin | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun user(init: UserDsl.() -> Unit): User { | |
return UserDsl().apply(init).build() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserDsl { | |
... | |
private val contactInfoDsl = UserContactInfoDsl() | |
private val rolesDsl = UserRolesDsl() | |
fun contactInfo(init: UserContactInfoDsl.() -> Unit) { | |
contactInfoDsl.apply(init) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserDsl { | |
... | |
private val contactInfoDsl = UserContactInfoDsl() | |
private val rolesDsl = UserRolesDsl() | |
... | |
fun build(): User { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun build(): User { | |
return User( | |
name = name, | |
contactInfo = ContactInfo( | |
email = "?", | |
phoneNumber = "?" | |
), | |
roles = emptyList() | |
) | |
} |
NewerOlder