exercises-cats
exercises-cats copied to clipboard
Traverse lesson, running examples with cats 1.0.0-MF
Hello people :).
I am trying to run the following code on a scala worksheet scala 2.12.4
, sbt 1.0.3
, cats 1.0.0-MF
:
import cats.Semigroup
import cats.data.{NonEmptyList, OneAnd, Validated, ValidatedNel}
import cats.implicits._
implicit def nelSemigroup[A]: Semigroup[NonEmptyList[A]] =
OneAnd.oneAndSemigroupK[List].algebra[A]
def parseIntEither(s: String): Either[NumberFormatException, Int] =
Either.catchOnly[NumberFormatException](s.toInt)
def parseIntValidated(s: String): ValidatedNel[NumberFormatException, Int] =
Validated.catchOnly[NumberFormatException](s.toInt).toValidatedNel
List("1", "2", "3").traverseU(parseIntEither)
List("1", "abc", "3").traverseU(parseIntEither)
But OneAnd apparently does not have oneAndSemigroupK, and I was also not able to find this in the scaladoc for cats. Maybe it is obvious, but I don't now how to implement the implicit so my List will have traverseU
Error is:
Error:(6, 11) value oneAndSemigroupK is not a member of object cats.data.OneAnd
OneAnd.oneAndSemigroupK[List].algebra[A]
^