scalawithcats / scala-with-cats

Source code for Scala with Cats
http://underscore.io/books/scala-with-cats
390 stars 129 forks source link

Unable to use the |+| syntax as presented in 2.5.4 #183

Closed nsadeh closed 4 years ago

nsadeh commented 4 years ago

I got

import cats.Monoid
import cats.syntax.semigroup._

def add[A](items: List[A])(implicit m: Monoid[A]): A = items.foldLeft(m.empty)(_ |+| _)

This gives me value |+| is not a member of type parameter A. Same error with context bound syntax.

What does work is

def add[A](items: List[A])(implicit m: Monoid[A]): A = items.foldLeft(m.empty)(m.combine _)

Is this an error in the book or is there a compiler arg I am missing?

noelwelsh commented 4 years ago

That code looks correct to me. You might try import cats.implicits._ instead of the imports you list, just to make sure nothing is missing. If you can upload a complete project I'll can take a look when time allows.

noelwelsh commented 4 years ago

I haven't heard back from you so I'm closing this.