IDEA: Auto generate Monoid[FunctionN]
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
Currently cats provides a Monoid instance for Function0 & Function1: https://github.com/typelevel/cats/blob/main/kernel/src/main/scala/cats/kernel/instances/FunctionInstances.scala#L109
While these are very useful, it is not uncommon in Scala to have functions of higher arities like Function2.
And, for all I can see, the implementation of such instances is just mechanical repetition.
Thus, this issue proposes the inclusion of the generation of all the repetitive code from trait Semigroup[Function2] until trait Monoid[Function22] extends Semigroup[Function22]
AFAIK the only downside of such a proposal is the increase in the JAR size; but, personally, I think this is a good addition since not having those instances can be surprising and somehow inconsistent.
PS: I see that we also have Group instances for Function0 & Function1. However, I am unfamiliar with that typeclass and I am not totally sure if such instance is valid for higher arities and if the implementation is equally mechanical; for how the code looks like it seems so, thus I leave it open to also include those in the generator.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked kernel/src/main/scala/cats/kernel/instances/FunctionInstances.scala and compare the existing Function0 and Function1 instances. Investigate how higher-arity instances could be generated and whether Group is valid beyond Function1. Done means the agreed generator produces Semigroup and Monoid instances through Function22, with Group included only if confirmed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100