scalawithcats / scala-with-cats

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

PrintableSyntax solution minor improvement #150

Closed rudwna closed 5 years ago

rudwna commented 5 years ago

From PrintableSyntax solution:

object PrintableSyntax {
  implicit class PrintableOps[A](value: A) {
    def format(implicit p: Printable[A]): String =
      Printable.format(value)

    def print(implicit p: Printable[A]): Unit =
      Printable.print(value)
  }
}

I'd suggest it's better to use the type class instance directly instead of depending on and mixing with Printable object which is another approach to using type class:

object PrintableSyntax {
  implicit class PrintableOps[A](value: A) {
    def format(implicit p: Printable[A]): String = p.format(value)
    def print(implicit p: Printable[A]): Unit = println(format(p))
  }
}

I think this better reflect the purpose of the exercise and the actual use case.

rudwna commented 5 years ago

This precede PR #151.