typelevel / typelevel/cats

Contravariant instances for `Op`

Open
#2,604 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

I noticed there are a number of possible contravariant instances for Op if we make some Arrow assumptions but currently none are there. Do we feel like any of these would be beneficial? For example, something like...

private[data] trait OpDecideable[Arr[_, _], R] extends Decideable[Op[Arr, R, ?]] with OpContravariantMonoidal[Arr, R] {
  implicit def Arr: ArrowChoice[Arr]
  implicit def M: Monoid[R]


  def sum[A, B](fa: Op[Arr, R, A], fb: Op[Arr, R, B]): Op[Arr, R, Either[A, B]] =
    Op(Arr.choice(fa.run, fb.run))
}

private[data] trait OpContravariantMonoidal[Arr[_, _], R] extends OpContravariant[Arr, R] with ContravariantMonoidal[Op[Arr, R, ?]] {
  implicit def Arr: Arrow[Arr]
  implicit def M: Monoid[R]

  def unit: Op[Arr, R, Unit] =
    Op(Arr.lift(Function.const(M.empty)))

  def product[A, B](fa: Op[Arr, R, A], fb: Op[Arr, R, B]): Op[Arr, R, (A, B)] =
    Op(Arr.compose(
      Arr.lift((M.combine _).tupled),
      Arr.split(fa.run, fb.run)))
}

private[data] trait OpContravariant[Arr[_, _], R] extends Contravariant[Op[Arr, R, ?]] {
  implicit def Arr: Arrow[Arr]

  def contramap[A, B](fa: Op[Arr, R, A])(f: B => A): Op[Arr, R, B] =
    Op(Arr.compose(fa.run, Arr.lift(f)))
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Op and the Arrow, Contravariant, ContravariantMonoidal, Decideable, and Monoid abstractions referenced in the proposal. Determine whether the proposed instances belong in Cats and what assumptions they require; done means a maintainer-approved scope, implementation location, and tests for the selected instances.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.