Code Monkey home page Code Monkey logo

Comments (3)

satorg avatar satorg commented on July 18, 2024

I don't think it is an oversight, but rather a very particular case that just has never been in demand previously.
For example, there's another method reverse that also construct a Semigroup instance out of the current one, but adding its counterpart to the object wont' help with type inference a lot:

Semigroup[String].reverse
// VERSUS
Semigroup.reverse[String]

When it comes to intercalate, then I agree it can come in handy, so I think it wouldn't hurt if we added it.

from cats.

johnynek avatar johnynek commented on July 18, 2024

It was an oversight. This style of typeclass encoding was used in the algebra project which predates cats and was absorbed into cats.

The motivation is that if you have def combine[A](a: A, b: A)(implicit ev: Semigroup[A]): A = ev.combine(a, b) you can avoid declaring the type, and get good JVM performance (the jit should be able to remove the indirection since is is statically the same as: implicitly[Semigroup[A]].combine(a, b) but without naming the type.

Semigroup.combine("foo", "bar")

Cats used an approach of just giving def apply[A: Semigroup]: Semigroup[A] ... but that requires naming the type as noted above.

There is a lot of boilerplate with the approach of duplicating methods from the typeclass into the object in order to hopefully get some nice type-inference cases. Personally, I have moved away from the style in most cases.

That said, I'm not opposed to adding it.

from cats.

igstan avatar igstan commented on July 18, 2024

Thanks, both. As it stands right now, it seems that only reverse and intercalate aren't exposed on the object, while the rest are (i.e., combine, combineN, combineAllOption). In addition, first, last and a few others are only available via the object.

What I'd do is add both intercalate and reverse on the object. The advantage is obvious for intercalate, while for reverse it would be just for consistency and because it doesn't take anything away DX-wise.

Does that sound good? If yes, I'll open a PR with both reverse and intercalate.

from cats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.