Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert List[ValidationNEL[String, Unit]] to ValidationNEL[String, Unit]

Tags:

scala

scalaz

Is there a standard way to flatten the left sides into a single list?

thanks!

like image 215
Alex Avatar asked May 21 '26 07:05

Alex


1 Answers

I'm not exactly sure what you're trying to do, but the Monoid instance should do the trick:

scala> List(
     |   println("test").successNel[String],
     |   "a".failNel[Unit],
     |   "b".failNel[Unit]
     | ).suml == Failure(NonEmptyList("a", "b"))
test
res0: Boolean = true

Where suml is a method that's pimped onto any collection full of something with a Monoid instance.

like image 71
Travis Brown Avatar answered May 24 '26 05:05

Travis Brown



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!