val bookiesOdds = for {
firstBoxer <- boxerDao.findByName(event.firstBoxer.firstName, event.firstBoxer.middleName, event.firstBoxer.lastName) map {_.getOrElse(throw new NoBoxerException("No boxer " + event.firstBoxer.fullName + " in database!"))}
secondBoxer <- boxerDao.findByName(event.secondBoxer.firstName, event.secondBoxer.middleName, event.secondBoxer.lastName) map {_.getOrElse(throw new NoBoxerException("No boxer " + event.secondBoxer.fullName + " in database!"))}
fight <- fightDao.findOrCreateFight(firstBoxer, secondBoxer, new java.sql.Date(event.date.getTime))
oddsId <- bookiesDao.createOdds(fight.id, event.periods.head.firstOdds.getOrElse(0), event.periods.head.drawOdds, event.periods.head.secondOdds.getOrElse(0), "pinnaclesports")
} yield {
fight
}
def findOrCreateFight(firstBoxer: BoxersRow, secondBoxer: BoxersRow, eventDate: java.sql.Date): Future[FightsRow] = {
for {
fight <- findByBoxersAndDate(firstBoxer, secondBoxer, eventDate)
if (fight == None)
f <- createAndFindFight(firstBoxer, secondBoxer, eventDate)
} yield fight.getOrElse(throw new NoFightException("Can not find a fight in DB"))
}
You don't need a for comprehension here:
findByBoxersAndDate(firstBoxer, secondBoxer, eventDate).getOrElse(createAndFindFight(firstBoxer, secondBoxer, eventDate)) should do
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.