3

I have the following class:

class MyBot[F[_] : FlatMap]

In this class I have a function:

private def handleCallback(): F[Boolean]

In my understanding this should work:

handleCallback().flatMap(..)

But it throws: cannot resolve symbol flatMap

What do I miss?

pme
  • 14,156
  • 3
  • 52
  • 95

2 Answers2

3

The solution of Mon Calamari did not fix my problem, but when checking FlatMap on the suggested Blog I spotted:

import cats.implicits._ which I missed - and fixed my problem - everything stayed the same.

pme
  • 14,156
  • 3
  • 52
  • 95
1

You'd need to summon an instance of FlatMap[F] and use its methods to flatMap:

class MyBot[F[_]](implicit F: FlatMap[F]) {

  def handleCallback: F[Boolean] = ...

  def flatMapCallback: F[Boolean] = F.flatMap(handleCallback) { bool => 
    ...
  }

}

More details in great blog from eed3si9n: http://eed3si9n.com/herding-cats/

Mon Calamari
  • 4,403
  • 3
  • 26
  • 44