Expand Gotlin language and tooling
This commit is contained in:
parent
8f4f858d86
commit
de1262b4cf
41 changed files with 6059 additions and 379 deletions
40
examples/mapping.gt
Normal file
40
examples/mapping.gt
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
data class AddressEntity(var city: String)
|
||||
data class AddressResponse(var city: String)
|
||||
|
||||
enum EntityState {
|
||||
Active
|
||||
Failed(String)
|
||||
}
|
||||
|
||||
enum ResponseState {
|
||||
Active
|
||||
Failed(String)
|
||||
Pending
|
||||
}
|
||||
|
||||
data class AccountEntity(
|
||||
var id: String,
|
||||
var address: *AddressEntity,
|
||||
var labels: List<String>,
|
||||
var state: EntityState
|
||||
)
|
||||
|
||||
data class AccountResponse(
|
||||
var address: *AddressResponse,
|
||||
var id: String,
|
||||
var labels: List<String>,
|
||||
var state: ResponseState
|
||||
)
|
||||
|
||||
fun main() {
|
||||
val entity = AccountEntity("account-1", AddressEntity("Berlin"), listOf("active"), EntityState::Active)
|
||||
val response = entity.mapTo<AccountResponse>()
|
||||
println(response.address.city)
|
||||
match (response.state) {
|
||||
ResponseState::Active -> { println("active") }
|
||||
ResponseState::Failed(reason) -> { println(reason) }
|
||||
ResponseState::Pending -> { println("pending") }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue