Skip to content

Instantly share code, notes, and snippets.

@tomaszperek
Created October 10, 2015 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaszperek/62242102ee9f4bdf2acf to your computer and use it in GitHub Desktop.
Save tomaszperek/62242102ee9f4bdf2acf to your computer and use it in GitHub Desktop.
ScalaTest spec demonstrating hsequence
class HsequenceSpec extends FlatSpec with Matchers with ScalaFutures {
import shapeless._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future._
"hsequence" should "calculate hzip of hlist" in {
val fs = successful(1) :: successful(true) :: successful("string") :: successful(1.0) :: HNil
val a :: b :: c :: d :: HNil = hsequence(fs).futureValue
a :: b :: c :: d :: HNil should equal(1 :: true :: "string" :: 1.0 :: HNil)
}
it should "work well with failures" in {
val exception: Exception = new scala.Exception("booo")
val fs = successful(1) :: successful(true) :: failed(exception) :: successful(1.0) :: HNil
val result = hsequence(fs)
whenReady(result.failed) { ex ⇒
ex should equal(exception)
}
}
it should "not compile if hlist has non-future element" in {
"""
|val fs = successful(1) :: successful(true) :: successful("Some string") :: HNil
|val result = hsequence(fs)
""".stripMargin should compile
"""
|val fs = successful(1) :: successful(true) :: "Some string" :: HNil
|val result = hsequence(fs)
""".stripMargin shouldNot compile
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment