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

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

python - Pygame screen.blit not working -

c# - Web API response xml language -