Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Created November 17, 2019 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulosuzart/5e729697aad68ec453658b93ee61b880 to your computer and use it in GitHub Desktop.
Save paulosuzart/5e729697aad68ec453658b93ee61b880 to your computer and use it in GitHub Desktop.
package example.controller
import arrow.fx.reactor.FluxK
import arrow.fx.reactor.extensions.fluxk.async.effect
import arrow.fx.reactor.value
import example.ParserService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Flux
@RestController
class ParserController(
private val parserService: ParserService
) {
@GetMapping("/parse")
fun parse(@RequestParam("keys") keys: Set<String>) = FluxK(Flux.fromIterable(keys)).flatMap { i ->
effect {
parserService.parse(i)
}
}.value()
}
package example.service
import arrow.core.Option
import arrow.extension
import arrow.typeclasses.Show
import org.springframework.stereotype.Component
import reactor.core.publisher.Mono
import java.util.*
interface ParserService {
suspend fun parse(semKey: String): ParseResult
}
data class ParseResult(val type: String) {
companion object
}
@extension
interface ResultShow : Show<ParseResult> {
override fun ParseResult.show(): String {
return "ParseResult: {type - $type}"
}
}
data class ParseConfig(val resolveLocation: Boolean, val locale: Option<Locale>)
@Component
class ReactiveParserService : ParserService {
override suspend fun parse(key: String): ParseResult {
val sample = aux()
val x = certainClient()
return ParseResult(key + sample)
}
suspend fun aux(): Int = 3
fun certainClient() : Mono<Int> = Mono.just(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment