Created
October 19, 2015 21:47
-
-
Save tomaszperek/4ebeafb121bc8e8ead56 to your computer and use it in GitHub Desktop.
How zip works with Monads
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
class ZipSpec extends FlatSpec with ScalaFutures with Matchers { | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scalaz.Scalaz._ | |
"zip" should "provide one future from args of futures" in { | |
val result = zip(successful(1), successful(true), successful("string"), successful(1.0)) | |
val (a, b, c, d) = result.futureValue | |
(a, b, c, d) should equal((1, true, "string", 1.0)) | |
} | |
it should "work with Lists too" in { | |
zip(List(1, 2), List(3, 4), List(5, 6)) should equal(List((1,3,5), (1,3,6), (1,4,5), (1,4,6), (2,3,5), (2,3,6), (2,4,5), (2,4,6))) | |
} | |
it should "work with Options too" in { | |
zip(Option(1), Option(3), Option(5)) should equal(Some(1,3,5)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment