Ted
Ted

Reputation: 1690

Kotlin Stream.asSequence() now requiring Stream.iterator().asSequence()

I am using java.net.HttpClient to issue a simple GET request where the response is of type HttpResponse<Stream>. However, even though Kotlin.streams has an asSequence() method, I now have to first convert the stream to an iterator before calling asSequence(). Why is this the case?

val client = HttpClient.newHttpClient()
val request = HttpRequest.newBuilder().let { builder ->
    builder.uri(URI("http://localhost:8000/response.txt"))
    builder.setHeader("Content-Type", "application/json")
    builder.GET()
    builder.build()
  }
val resp: HttpResponse<Stream<String>> = client.send(request, HttpResponse.BodyHandlers.ofLines())
  //used to be resp.body().asSequence().map{
  resp.body().iterator().asSequence().map {
    println("${it.toString()}")
  }

Upvotes: 0

Views: 249

Answers (1)

Ted
Ted

Reputation: 1690

In the build.gradle.kts I was referencing the wrong version of the jdk. The problem resolved when I imported org.jetbrains.kotlin:kotlin-stdlib-jdk8 as a dependency.

Upvotes: 1

Related Questions