This file contains hidden or 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
def getSystemStatusInfo(id: String): Task[SystemStatusInfo] = { | |
map2(fetchSystemTask(id), fetchSystemStatusTask(id))((system, systemStatus) => SystemStatusInfo(system, systemStatus)) | |
} |
This file contains hidden or 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
def map2[A, B, C](task1: Task[A], task2: Task[B])(combine: (A, B) => C): Task[C] = { | |
Task.mapBoth(task1, task2)(combine) | |
} |
This file contains hidden or 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
def getSystemStatusInfo(id: String): Future[SystemStatusInfo] = { | |
map2(fetchSystem(id), fetchSystemStatus(id))((system, systemStatus) => SystemStatusInfo(system, systemStatus)) | |
} |
This file contains hidden or 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
def map2[A, B, C](future1: Future[A], future2: Future[B])(combine: (A, B) => C): Future[C] = { | |
future1.zip(future2).map { | |
case (result1, result2) => combine(result1, result2) | |
} | |
} |
This file contains hidden or 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
def getSystemStatusInfo(id: String): Future[SystemStatusInfo] = { | |
val systemFuture = fetchSystem(id) | |
val systemStatusFuture = fetchSystemStatus(id) | |
systemFuture.zip(systemStatusFuture).map { | |
case (system, systemStatus) => SystemStatusInfo(system, systemStatus) | |
} | |
} |
This file contains hidden or 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 scala.concurrent.ExecutionContext.Implicits.global | |
def getSystemStatusInfo(id: String): Future[SystemStatusInfo] = { | |
for { | |
system <- fetchSystem(id) | |
systemStatus <- fetchSystemStatus(id) | |
} yield SystemStatusInfo(system, systemStatus) | |
} |
This file contains hidden or 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
def getSystemStatusInfo(id: String): Option[SystemStatusInfo] = { | |
for { | |
systemStatus <- systemStatusMap.get(id) | |
system <- systemsMap.get(id) | |
} yield SystemStatusInfo(system, systemStatus) | |
} |
This file contains hidden or 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
def getSystemStatusInfo(id: String): Option[SystemStatusInfo] = { | |
for { | |
system <- systemsMap.get(id) | |
systemStatus <- systemStatusMap.get(id) | |
} yield SystemStatusInfo(system, systemStatus) | |
} |
This file contains hidden or 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
scala> getSystemStatusInfo("consumer_desktop") | |
res20: Option[SystemStatusInfo] = Some(SystemStatusInfo(System(consumer_desktop,realestate.com.au desktop site,consumer_web),Red)) | |
scala> getSystemStatusInfo("no_such_system_id") | |
res21: Option[SystemStatusInfo] = None |
This file contains hidden or 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
def getSystemStatusInfo(id: String): Option[SystemStatusInfo] = { | |
val systemOption = systemsMap.get(id) | |
systemOption.flatMap(system => { | |
val systemStatusOption = systemStatusMap.get(id) | |
systemStatusOption.map(systemStatus => SystemStatusInfo(system, systemStatus)) | |
}) | |
} |