scala - Converting a foreach into contains forall matcher -


i have following expression in spec, intention of ensuring each element has value distancetoend close sum of distancefromprevious values of elements following it.

foo.tails.foreach {   case h +: t => h.distancetoend.miles must     becloseto(t.map(_.distancefromprevious.miles).sum, 10e-10)   case _ => ok } 

ideally, should in form foo.tails must contain { ... }.forall, have trouble understanding how create necessary valuecheck parameter contains. how convert particular example?

unfortunately type inference doesn't work partial functions need match explicitly:

 foo.tails must contain { ts: list[foo] =>    ts match {      case h +: t => h.distancetoend.miles must        becloseto(t.map(_.distancefromprevious.miles).sum, 10e-10)      case _ => ok    } }.forall 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -