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
def condition: Boolean = ... | |
def action1(): Unit = ... | |
def action2(): Unit = ... | |
if (condition) { | |
action1() | |
} else { | |
action2() | |
} |
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
def condition: Future[Boolean] = ... | |
def action1(): Future[Unit] = ... | |
def action2(): Future[Unit] = ... | |
condition.flatMap( | |
if (_) | |
action1() | |
else | |
action2() |
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
def condition1: Boolean = ... | |
def condition2: Boolean = ... | |
def condition3: Boolean = ... | |
if (condition1 && (condition2 || condition3)) ... |
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
implicit class FutureOfBooleanExtensions(val future: Future[Boolean]) extends AnyVal { | |
def &&(other: => Future[Boolean]): Future[Boolean] = | |
future.flatMap(value => if (!value) Future.successful(false) else other) | |
def ||(other: => Future[Boolean]): Future[Boolean] = | |
future.flatMap(value => if (value) Future.successful(true) else other) | |
} |
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
def condition1: Future[Boolean] = ... | |
def condition2: Future[Boolean] = ... | |
def condition3: Future[Boolean] = ... | |
val condition = condition1 && (condition2 || condition3) | |
condition.flatMap( | |
if (_) | |
... | |
else | |
... |
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
implicit class BooleanToFutureExtensions(val v: Boolean) extends AnyVal { | |
def &&(other: => Future[Boolean]): Future[Boolean] = | |
if (v) other else Future.successful(false) | |
def ||(other: => Future[Boolean]): Future[Boolean] = | |
if (v) Future.successful(true) else other | |
} |
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
def condition1: Boolean = ... | |
def condition2: Boolean = ... | |
def condition3: Future[Boolean] = ... | |
val condition = condition1 && (condition2 || condition3) | |
condition.flatMap( | |
if (_) | |
... | |
else | |
... |
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
implicit class FutureOfBooleanExtensions(val future: Future[Boolean]) extends AnyVal { | |
def &&(other: => BooleanOrFutureOfBoolean): Future[Boolean] = | |
v.flatMap( | |
if (_) | |
other match { | |
case Bool(otherValue) => Future.successful(otherValue) | |
case Fut(future) => future | |
} | |
else | |
Future.successful(false) |
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
def getMovie: Future[Movie] | |
def getActors(movie: Movie): Future[Seq[Actor]] | |
def getPlot(movie: Movie): Future[MoviePlot] | |
for { | |
movie <- getMovie | |
actors <- getActors(movie) | |
plot <- getPlot(movie) | |
} yield MovieDescription(movie, actors, plot) |
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
def hasPermissions: Future[Boolean] | |
for { | |
isPermitted <- hasPermissions | |
if isPermitted | |
movie <- getMovie | |
if !movie.hidden | |
actors <- getActors(movie) | |
plot <- getPlot(movie) | |
} yield MovieDescription(movie, actors, plot) |