evolution-gaming / cats-helper

Helpers for cats & cats-effect
MIT License
49 stars 17 forks source link

Add convenient way to call FromFuture #115

Closed FunFunFine closed 2 years ago

FunFunFine commented 2 years ago

Currently it's not possible to call apply on the classic 'summon' method:

val future: Future[Unit] = ???

def example[F[_]: FromFuture] = {
  val fa0 = FromFuture[F[_]](future) //fails to compile
  val fa1 = FromFuture.apply[F](future) //fails to compile
  val fa2 = FromFuture[F].apply(future) //compiles, but triggers you to replace apply with application
  val fa3 = FromFuture.summon[F](future) //fails to compile
  val fa4 = FromFuture.summon[F].apply(future) //compiles, but ugly
}

And having FromFuture instance as an explicit parameter is not always convenient.

This PR introduces new partially-applied method to call this like that:

val fa = FromFuture.defer[F](future)

Note that it is possible to achieve the fa0 way of calling it just by renaming new defer method to apply, but this will break existing apply method, which summons the instance. Perhaps it's possible to deprecate it in favour of summon method, and then after its removal introduce said apply method.

t3hnar commented 2 years ago

released under v2.7.0