coulomb icon indicating copy to clipboard operation
coulomb copied to clipboard

value types that are functors, and bifunctor operations

Open erikerlandson opened this issue 4 years ago • 0 comments

the integration with Refined turned up an interesting pattern. the implementations of operations looked like this:

    new UnitAdd[Refined[V1, P1], U1, Refined[V2, P2], U2] {
      def vadd(v1: Refined[V1, P1], v2: Refined[V2, P2]): Refined[V1, P1] = {
        add.vadd(v1.value, v2.value).applyPred[P1]
      }

The pattern was un-packing lhs and rhs payloads, operating on them, and re-packing them. This basic logic generalizes to operands that are functors, particularly Option, Either, etc. But possibly even other nontrivial functors like Seq

It also suggests that these operations themselves are bifunctors. Can they be implemented using cats Bifunctor and bimap ?

erikerlandson avatar Apr 24 '20 13:04 erikerlandson