Skip to content

Traverse lesson, running examples with cats 1.0.0-MF #63

@Fabs

Description

@Fabs

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]
         ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions