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
val futureSum: Future[Int] = for { | |
a <- futureA | |
b <- futureB | |
c <- futureC | |
} yield a + b + c |
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
results: Future[Seq[Int]] = Future.sequence(Seq(futureA, futureB, futureC)) |
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
Future.sequence(Seq(futureA, futureB, futureC)).map(_.sum) |
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
val aAndB: Future[(A, B)] = futureA zip futureB |
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
val aAndBAndC: Future[((A, B), C)] = futureA zip futureB zip futureC |
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 zip3[A, B, C](fA: Future[A], fB: Future[B], fc: Future[C]): Future[(A, B, C)] = | |
(fA zip fB zip fC) map { case ((a, b), c) => (a, b, c)} |
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 acceptSameSize[T](l: Seq[List[T]]): Unit = { | |
if (l.exists(_.size != 2)) throw new IllegalArgumentException("list has incorrect size!") | |
// do something | |
} |
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 acceptSameSize[T, N <: Nat](l: Seq[Sized[Seq[T], N]]) = { | |
//do something | |
} |
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
val args = List(Sized("abc", "def"), Sized("ghi", "jkl")) | |
acceptSameSize(args) |
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
val args = List(Sized("abc", "def"), Sized("ghi", "jkl", "mno")) | |
acceptSameSize(args) |