NewtypeCovariantK
For building newtypes over types that have a covariant type parameter (higher-kinded types).
Example:
// Only needed for type-class derivation
import cats._
import cats.implicits._
type NonEmptyList[A] = NonEmptyList.Type[A]
object NonEmptyList extends NewtypeCovariantK[List] {
def apply[A](head: A, tail: A*): NonEmptyList[A] =
unsafeCoerce(head :: tail.toList)
def unapply[F[_], A](list: F[A])(
implicit ev: F[A] =:= NonEmptyList[A]
): Some[(A, List[A])] = {
val l = value(list)
Some((l.head, l.tail))
}
implicit def eq[A: Eq]: Eq[NonEmptyList[A]] =
derive
implicit val traverse: Traverse[NonEmptyList] =
deriveK
implicit val monad: Monad[NonEmptyList] =
deriveK
}
NOTE: the type-parameter is covariant.
- See also:
NewtypeK for working with invariance.
trait NewtypeCovariantTraitK[Src]
trait NewEncodingK[Src]
class Object
trait Matchable
class Any