softwaremill / magnolia

Easy, fast, transparent generic derivation of typeclass instances
https://softwaremill.com/open-source/
Apache License 2.0
760 stars 116 forks source link

Make Magnolia implicit prioritization configurable #58

Open Qthunder opened 6 years ago

Qthunder commented 6 years ago

Currently, when recursively looking for implicits, Magnolia accords any other implicit higher priority than the Magnolia derived implicit itself.

It would be useful to have this behaviour configurable at the point of the macro invocation.

propensive commented 6 years ago

If we discover that the only way to achieve this is to hardwire the behavior into the Magnolia macro, i.e. the derivation object, the best solution (I think) would be to provide two different macro implementation methods inside the Magnolia object. One of these would exhibit the current behavior, while the other would give priority to Magnolia-derived instances over other typeclass instances found by implicit search.

Essentially, the current implementation of the gen method would take and additional Boolean parameter concerning the prioritization, and two new implementations would be provided, one calling it with true, the other with false.

The two challenges would be to,

  1. have different logic, dependent on this Boolean value, and
  2. pick good names for these two methods
propensive commented 6 years ago

I think the recent change by @fommil to make the implicitness of the gen method significant probably fixes this, so I'm closing.