0

Using scalactic, one can convert an Every to a List like this:

scala> Every(1,2,3).toList
res6: List[Int] = List(1, 2, 3)

How can I perform the reverse operation, though, i.e. try to convert a List or an Iterable to an Every? Is there a built-in method that does this?

jjst
  • 2,631
  • 2
  • 22
  • 34

1 Answers1

1

Simply:

val everyOpt: Option[Every[Int]] = Every.from(List(1, 2, 3))

If the list is known to be non empty:

val every: Every[Int] = Every.from(List(1, 2, 3)).get
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
  • Doh! I'll remember to look up the documentation for the companion object next time. For reference: http://doc.scalatest.org/2.2.6/#org.scalactic.Every$ – jjst Feb 03 '16 at 22:28