Comments (3)
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.
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.
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)
- Inconsistent behaviour when using Eval as Applicative
- `Tuple1SemigroupalOps` methods have different names from other `TupleNSemigroupalOps` classes HOT 3
- Instances for Currency HOT 7
- EitherT[Option, ?, ?]] can't be used as a bifunctor HOT 5
- trait EuclidianRing should not be a Ring HOT 4
- OutOfMemoryError when IO.uncancelable is used in recursive function HOT 1
- ambiguous implicit resolution of `Show.ContravariantShow[immutable.SortedMap[K, V]]` HOT 1
- Should Monad extend Defer? HOT 11
- Support Scala Native 0.5 HOT 3
- Adding an alternative version of the method whenA with a different signature
- `Eval` thread safety HOT 4
- Optimize `distinct`/`distinctBy` implementations for non-empty collections
- [PROPOSAL] Aliases for methods `traverse_` and `sequence_` HOT 7
- (very breaking) change in Future instances? HOT 5
- Reveal internal but public identifiers and make them `private[cats]`
- Cats Order needs an `orElseBy` combinator HOT 8
- Loss of type safety in scala 3 under certain conditions
- Make Later covariant in its type parameter
- Ease awkward constructions when doing something before raising HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cats.