NewtypeCovariantK

monix.newtypes.NewtypeCovariantK
abstract class NewtypeCovariantK[Src[_]]

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.

Attributes

See also

NewtypeK for working with invariance.

Source
NewtypeK.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Type members

Inherited and Abstract types

override opaque type Type[+A]

Attributes

Inherited from:
NewtypeCovariantTraitK (hidden)
Source
NewEncodingK.scala

Value members

Inherited methods

final inline protected def derive[F[_], A](using ev: F[Src[A]]): F[Type[A]]

Attributes

Inherited from:
NewEncodingK (hidden)
Source
NewEncodingK.scala
final inline protected def deriveK[F[_[_]]](using ev: F[Src]): F[Type]

Attributes

Inherited from:
NewEncodingK (hidden)
Source
NewEncodingK.scala
final inline protected def unsafeCoerce[A](value: Src[A]): Type[A]

Attributes

Inherited from:
NewEncodingK (hidden)
Source
NewEncodingK.scala

Extensions

Inherited extensions

extension [A](self: Type[A])
final inline def value: Src[A]

Attributes

Inherited from:
NewEncodingK (hidden)
Source
NewEncodingK.scala

Implicits

Inherited implicits

final implicit def extractor[A]: Aux[Type[A], Src[A]]

Attributes

Inherited from:
NewEncodingK (hidden)
Source
NewEncodingK.scala
implicit def typeName[A : TypeInfo]: TypeInfo[Type[A]]

Attributes

Inherited from:
NewEncodingK (hidden)
Source
NewEncodingK.scala