I have a method that should convert a list to an Option
of an object, or None
if the list is empty.
def listToOption(myList: List[F
import scalaz._; import Scalaz._
myList.toNel.map(Bar)
toNel
- is "to non-empty list" here, it returns Option[NonEmptyList]
for safety:
scala> case class Bar(a: NonEmptyList[Int])
defined class Bar
scala> List(1,2,3).toNel.map(Bar)
res64: Option[Bar] = Some(Bar(NonEmptyList(1, 2, 3)))
scala> List[Int]().toNel.map(Bar)
res65: Option[Bar] = None