Created
November 17, 2019 10:33
-
-
Save paulosuzart/5e729697aad68ec453658b93ee61b880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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