问题
I was learning Cats library and found *
as a generic type, like that:
implicit def catsDataSemigroupKForValidated[A](implicit A: Semigroup[A]): SemigroupK[Validated[A, *]] =
new SemigroupK[Validated[A, *]] {
def combineK[B](x: Validated[A, B], y: Validated[A, B]): Validated[A, B] = x match {
case v @ Valid(_) => v
case Invalid(ix) =>
y match {
case Invalid(iy) => Invalid(A.combine(ix, iy))
case v @ Valid(_) => v
}
}
}
My guess is that the *
is used, because the combineK
method return Validated[A, B]
so there is no need to specify generic type. Or it could be Any
type (like Inteliij is suggested). I would be very glad for your explanations.
回答1:
The cats code you are looking at is master branch, which is for Dotty (Scala 3). *
is a type parameter placeholder in 3.0:
https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html
Note that it is already deprecated in 3.2 and removed in 3.3 in favor for _
.
来源:https://stackoverflow.com/questions/61565393/what-does-the-mean-in-a-generic-type