Expand Gotlin language and tooling
This commit is contained in:
parent
8f4f858d86
commit
de1262b4cf
41 changed files with 6059 additions and 379 deletions
22
examples/enums.gt
Normal file
22
examples/enums.gt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package main
|
||||
|
||||
enum PaymentResult {
|
||||
Accepted(String)
|
||||
Rejected(String)
|
||||
Pending
|
||||
}
|
||||
|
||||
fun describe(result: PaymentResult): String {
|
||||
var description = ""
|
||||
match (result) {
|
||||
PaymentResult::Accepted(id) -> { description = "accepted " + id }
|
||||
PaymentResult::Rejected(reason) -> { description = "rejected " + reason }
|
||||
PaymentResult::Pending -> { description = "pending" }
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val result = PaymentResult::Accepted("payment-1")
|
||||
println(describe(result))
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ class EpicControllerImpl(val db: *bun.DB) {
|
|||
}
|
||||
|
||||
worker Counter {
|
||||
val counter = 0
|
||||
var counter = 0
|
||||
|
||||
fun getCount(): Int {
|
||||
return counter
|
||||
|
|
|
|||
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") }
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ class PrefixGreeter(val prefix: String): Greeter {
|
|||
}
|
||||
|
||||
worker Counter {
|
||||
val count = 0
|
||||
var count = 0
|
||||
|
||||
fun increment() {
|
||||
count += 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue