=htp refactor tuple join to foldLeft-based implementation, unify tuple operations

This commit is contained in:
Mathias 2014-10-15 10:06:36 +02:00
parent 129958d039
commit 33ddabbc9f
12 changed files with 124 additions and 164 deletions

View file

@ -4,23 +4,26 @@
package akka.http.server.util
import org.scalatest.{ Matchers, FreeSpec }
import org.scalatest.{ Matchers, WordSpec }
class TupleOpsSpec extends FreeSpec with Matchers {
class TupleOpsSpec extends WordSpec with Matchers {
import TupleOps._
"The TupleOps should" - {
"The TupleOps" should {
"support folding over tuples using a binary poly-function" - {
"example 1" in {
object Funky extends Poly2 {
implicit def step1 = at[Double, Int](_ + _)
implicit def step2 = at[Double, Symbol]((d, s) (d + s.name.tail.toInt).toByte)
implicit def step3 = at[Byte, String]((byte, s) byte + s.toLong)
}
(1, 'X2, "3").foldLeft(0.0)(Funky) shouldEqual 6L
"support folding over tuples using a binary poly-function" in {
object Funky extends BinaryPolyFunc {
implicit def step1 = at[Double, Int](_ + _)
implicit def step2 = at[Double, Symbol]((d, s) (d + s.name.tail.toInt).toByte)
implicit def step3 = at[Byte, String]((byte, s) byte + s.toLong)
}
(1, 'X2, "3").foldLeft(0.0)(Funky) shouldEqual 6L
}
"support joining tuples" in {
(1, 'X2, "3") join () shouldEqual (1, 'X2, "3")
() join (1, 'X2, "3") shouldEqual (1, 'X2, "3")
(1, 'X2, "3") join (4.0, 5L) shouldEqual (1, 'X2, "3", 4.0, 5L)
}
}
}