Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scala greeter example #95

Merged
merged 11 commits into from
Feb 5, 2024
Merged

Add Scala greeter example #95

merged 11 commits into from
Feb 5, 2024

Conversation

gvdongen
Copy link
Collaborator

@gvdongen gvdongen commented Feb 1, 2024

  • Adds a Scala keyed greeter examples


name := "hello-world-http"
version := "1.0"
scalaVersion := "2.13.12"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't scala 2.13 legacy? shouldn't we provide an example for scala 3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't scala 2.13 still used more? I can switch though. Probably it matter little here, if all dependencies support Scala 3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK the data about usage of scala 2.13 but I would rather prefer to show an example with the latest Scala version. If someone is stuck on 2.13, they'll probably find a way to make it working.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this one and try adding a Scala 3 example as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this one and try adding a Scala 3 example as well

+1 for this approach.

Copy link
Contributor

@tillrohrmann tillrohrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for creating this PR @gvdongen. This is really good for helping users who are interested in Scala and SBT :-) +1 for merging and tackling Scala 3 as a potential follow-up.

import io.grpc.stub.StreamObserver

class Greeter extends GreeterImplBase with RestateService {
private val COUNT = StateKey.of[Integer]("count", CoreSerdes.INT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't statics go into a companion object usually in Scala?

val count = ctx.get(COUNT).orElse(Integer.valueOf(1))
ctx.set(COUNT, Integer.valueOf(count + 1))

responseObserver.onNext(GreetResponse.newBuilder.setMessage("Hello " + request.getName + " for the " + count + " time!").build)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
responseObserver.onNext(GreetResponse.newBuilder.setMessage("Hello " + request.getName + " for the " + count + " time!").build)
responseObserver.onNext(GreetResponse.newBuilder.setMessage(s"Hello ${request.getName} for the ${count} time!").build)

@gvdongen gvdongen merged commit 2b60232 into main Feb 5, 2024
2 checks passed
@gvdongen gvdongen deleted the issue90 branch February 5, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants