-
-
Save jarekratajski/2adb5680b28388339636578ccf6ab6f8 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
import java.util.{Collections, UUID} | |
import reactor.core.publisher.{Flux, Mono} | |
class Overreactive { | |
class POC { | |
def ws = new WS() | |
def db = new DB() | |
def doIt(name: String): Flux[String] = { | |
val paid: Mono[(java.util.List[Item], UUID)] = for { | |
user <- ws.findUserByName(name) | |
contains <- db.contains(user.getSsn) | |
persistentUser <- if (!contains) db.save(user) else Mono.just(user) | |
cart <- loadCart(persistentUser) | |
total <- Mono.just(cart.stream().mapToDouble(_.getPrice).sum()) | |
uuid <- pay(total) | |
} yield ((cart, uuid)) | |
for { | |
allPaidItems <- paid.flux() | |
paidItem <- Flux.fromIterable(allPaidItems._1) | |
sent <- sendEmail(paidItem, allPaidItems._2) | |
} yield (sent) | |
} | |
private def sendEmail(item: Item, id: UUID) = Mono.just("aa") | |
private def pay(total: Double) = Mono.just(UUID.randomUUID) | |
private def loadCart(user: User): Mono[java.util.List[Item]] | |
= Flux.fromIterable(Collections.emptyList[Item]).collectList() | |
} | |
class WS { | |
def findUserByName(name: String): Mono[User] = ??? | |
} | |
class DB { | |
def contains(ssn: String): Mono[Boolean] = Mono.just(false) | |
def save(user: User): Mono[User] = Mono.just(user) | |
} | |
class Item { | |
def getPrice = 0 | |
} | |
class User { | |
def getSsn = "ssn" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment