Weird abstract type construct in a method in scala

51 views Asked by At

browsing cats code, and found this

object ops {
    implicit def toAllInvariantOps[F[_], A](target: F[A])(implicit tc: Invariant[F]): AllOps[F, A] {
      type TypeClassType = Invariant[F]
    } =
      new AllOps[F, A] {
        type TypeClassType = Invariant[F]
        val self: F[A] = target
        val typeClassInstance: TypeClassType = tc
      }
  }

I do not under the {type TypeClassType = Invariant[F]} followed by =

If the function definition (parameter declaration) end with

implicit def toAllInvariantOps[F[_], A](target: F[A])(implicit tc: Invariant[F]): AllOps[F, A]

and the body is

=
      new AllOps[F, A] {
        type TypeClassType = Invariant[F]
        val self: F[A] = target
        val typeClassInstance: TypeClassType = tc
      }

What exactly is {type TypeClassType = Invariant[F]}

I mean from a syntax point of you i do not understand what it does in there ? Never seen a function written like that. Help ?

0

There are 0 answers