GoogleCloudPlatform / GoogleCloudPlatform/kotlin-samples

Cleaner object creation

Open
#64 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
286
Forks
85
PR merge metrics
No merged PRs in 30d

Description

In the [sample code](https://github.com/GoogleCloudPlatform/kotlin-samples/blob/master/run/grpc-hello-world-streaming/src/main/kotlin/io/grpc/examples/helloworld/HelloWorldClient.kt) you initialize a HelloRequest object with:
```
val request = HelloRequest.newBuilder().setName(name).build()
```

It would be a big help if you could generate a Kotlin builder for each user protobuf object:
```
fun helloRequest(block: HelloRequest.Builder.() -> Unit): HelloRequest =
HelloRequest.newBuilder().let {
block.invoke(it)
it.build()
}
```

which would allow for much cleaner object creation:
```
val request = helloRequest { this.name = name }
```

[One of your fellow Googlers](https://github.com/googleapis/gapic-generator-kotlin) uses this approach and it makes for less cluttered user code.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.