Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Simulacrum Scalafix #3424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion alleycats-core/src/main/scala/alleycats/ConsK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package alleycats

import cats.SemigroupK
import simulacrum.typeclass
import scala.annotation.implicitNotFound

@typeclass trait ConsK[F[_]] {
@implicitNotFound("Could not find an instance of ConsK for ${F}")
@typeclass trait ConsK[F[_]] extends Serializable {
def cons[A](hd: A, tl: F[A]): F[A]
}

Expand All @@ -12,4 +14,43 @@ object ConsK {
new ConsK[F] {
def cons[A](hd: A, tl: F[A]): F[A] = s.combineK(p.pure(hd), tl)
}

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
/**
* Summon an instance of [[ConsK]] for `F`.
*/
@inline def apply[F[_]](implicit instance: ConsK[F]): ConsK[F] = instance

trait Ops[F[_], A] {
type TypeClassType <: ConsK[F]
def self: F[A]
val typeClassInstance: TypeClassType
}
trait AllOps[F[_], A] extends Ops[F, A]
trait ToConsKOps {
implicit def toConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): Ops[F, A] {
type TypeClassType = ConsK[F]
} = new Ops[F, A] {
type TypeClassType = ConsK[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToConsKOps
object ops {
implicit def toAllConsKOps[F[_], A](target: F[A])(implicit tc: ConsK[F]): AllOps[F, A] {
type TypeClassType = ConsK[F]
} = new AllOps[F, A] {
type TypeClassType = ConsK[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}

/****************************************************************************/
/* END OF SIMULACRUM-MANAGED CODE */
/****************************************************************************/

}
45 changes: 44 additions & 1 deletion alleycats-core/src/main/scala/alleycats/Empty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import cats.{Eq, Monoid}
import cats.syntax.eq._

import simulacrum.typeclass
import scala.annotation.implicitNotFound

@typeclass trait Empty[A] {
@implicitNotFound("Could not find an instance of Empty for ${A}")
@typeclass trait Empty[A] extends Serializable {
def empty: A

def isEmpty(a: A)(implicit ev: Eq[A]): Boolean =
Expand All @@ -20,6 +22,47 @@ object Empty extends EmptyInstances0 {
new Empty[A] { lazy val empty: A = a }

def fromEmptyK[F[_], T](implicit ekf: EmptyK[F]): Empty[F[T]] = ekf.synthesize[T]

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
/**
* Summon an instance of [[Empty]] for `A`.
*/
@inline def apply[A](implicit instance: Empty[A]): Empty[A] = instance

trait Ops[A] {
type TypeClassType <: Empty[A]
def self: A
val typeClassInstance: TypeClassType
def isEmpty(implicit ev: Eq[A]): Boolean = typeClassInstance.isEmpty(self)(ev)
def nonEmpty(implicit ev: Eq[A]): Boolean = typeClassInstance.nonEmpty(self)(ev)
}
trait AllOps[A] extends Ops[A]
trait ToEmptyOps {
implicit def toEmptyOps[A](target: A)(implicit tc: Empty[A]): Ops[A] {
type TypeClassType = Empty[A]
} = new Ops[A] {
type TypeClassType = Empty[A]
val self: A = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToEmptyOps
object ops {
implicit def toAllEmptyOps[A](target: A)(implicit tc: Empty[A]): AllOps[A] {
type TypeClassType = Empty[A]
} = new AllOps[A] {
type TypeClassType = Empty[A]
val self: A = target
val typeClassInstance: TypeClassType = tc
}
}

/****************************************************************************/
/* END OF SIMULACRUM-MANAGED CODE */
/****************************************************************************/

}

private[alleycats] trait EmptyInstances0 extends compat.IterableEmptyInstance with EmptyInstances1
Expand Down
46 changes: 45 additions & 1 deletion alleycats-core/src/main/scala/alleycats/EmptyK.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
package alleycats

import simulacrum.typeclass
import scala.annotation.implicitNotFound

@typeclass trait EmptyK[F[_]] { self =>
@implicitNotFound("Could not find an instance of EmptyK for ${F}")
@typeclass trait EmptyK[F[_]] extends Serializable { self =>
def empty[A]: F[A]

def synthesize[A]: Empty[F[A]] =
new Empty[F[A]] {
def empty: F[A] = self.empty[A]
}
}

object EmptyK {

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
/**
* Summon an instance of [[EmptyK]] for `F`.
*/
@inline def apply[F[_]](implicit instance: EmptyK[F]): EmptyK[F] = instance

trait Ops[F[_], A] {
type TypeClassType <: EmptyK[F]
def self: F[A]
val typeClassInstance: TypeClassType
}
trait AllOps[F[_], A] extends Ops[F, A]
trait ToEmptyKOps {
implicit def toEmptyKOps[F[_], A](target: F[A])(implicit tc: EmptyK[F]): Ops[F, A] {
type TypeClassType = EmptyK[F]
} = new Ops[F, A] {
type TypeClassType = EmptyK[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToEmptyKOps
object ops {
implicit def toAllEmptyKOps[F[_], A](target: F[A])(implicit tc: EmptyK[F]): AllOps[F, A] {
type TypeClassType = EmptyK[F]
} = new AllOps[F, A] {
type TypeClassType = EmptyK[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}

/****************************************************************************/
/* END OF SIMULACRUM-MANAGED CODE */
/****************************************************************************/

}
44 changes: 43 additions & 1 deletion alleycats-core/src/main/scala/alleycats/Extract.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package alleycats
import cats.{CoflatMap, Comonad}

import simulacrum.typeclass
import scala.annotation.implicitNotFound

@typeclass trait Extract[F[_]] {
@implicitNotFound("Could not find an instance of Extract for ${F}")
@typeclass trait Extract[F[_]] extends Serializable {
def extract[A](fa: F[A]): A
}

Expand All @@ -22,4 +24,44 @@ object Extract {
override def map[A, B](fa: F[A])(f: A => B): F[B] = cf.map(fa)(f)
def coflatMap[A, B](fa: F[A])(f: F[A] => B): F[B] = cf.coflatMap(fa)(f)
}

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
/**
* Summon an instance of [[Extract]] for `F`.
*/
@inline def apply[F[_]](implicit instance: Extract[F]): Extract[F] = instance

trait Ops[F[_], A] {
type TypeClassType <: Extract[F]
def self: F[A]
val typeClassInstance: TypeClassType
def extract: A = typeClassInstance.extract[A](self)
}
trait AllOps[F[_], A] extends Ops[F, A]
trait ToExtractOps {
implicit def toExtractOps[F[_], A](target: F[A])(implicit tc: Extract[F]): Ops[F, A] {
type TypeClassType = Extract[F]
} = new Ops[F, A] {
type TypeClassType = Extract[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToExtractOps
object ops {
implicit def toAllExtractOps[F[_], A](target: F[A])(implicit tc: Extract[F]): AllOps[F, A] {
type TypeClassType = Extract[F]
} = new AllOps[F, A] {
type TypeClassType = Extract[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}

/****************************************************************************/
/* END OF SIMULACRUM-MANAGED CODE */
/****************************************************************************/

}
45 changes: 44 additions & 1 deletion alleycats-core/src/main/scala/alleycats/One.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package alleycats
import cats.Eq
import cats.syntax.eq._
import simulacrum.typeclass
import scala.annotation.implicitNotFound

@typeclass trait One[A] {
@implicitNotFound("Could not find an instance of One for ${A}")
@typeclass trait One[A] extends Serializable {
def one: A

def isOne(a: A)(implicit ev: Eq[A]): Boolean =
Expand All @@ -17,4 +19,45 @@ import simulacrum.typeclass
object One {
def apply[A](a: => A): One[A] =
new One[A] { lazy val one: A = a }

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
/**
* Summon an instance of [[One]] for `A`.
*/
@inline def apply[A](implicit instance: One[A]): One[A] = instance

trait Ops[A] {
type TypeClassType <: One[A]
def self: A
val typeClassInstance: TypeClassType
def isOne(implicit ev: Eq[A]): Boolean = typeClassInstance.isOne(self)(ev)
def nonOne(implicit ev: Eq[A]): Boolean = typeClassInstance.nonOne(self)(ev)
}
trait AllOps[A] extends Ops[A]
trait ToOneOps {
implicit def toOneOps[A](target: A)(implicit tc: One[A]): Ops[A] {
type TypeClassType = One[A]
} = new Ops[A] {
type TypeClassType = One[A]
val self: A = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToOneOps
object ops {
implicit def toAllOneOps[A](target: A)(implicit tc: One[A]): AllOps[A] {
type TypeClassType = One[A]
} = new AllOps[A] {
type TypeClassType = One[A]
val self: A = target
val typeClassInstance: TypeClassType = tc
}
}

/****************************************************************************/
/* END OF SIMULACRUM-MANAGED CODE */
/****************************************************************************/

}
43 changes: 42 additions & 1 deletion alleycats-core/src/main/scala/alleycats/Pure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package alleycats

import cats.{Applicative, FlatMap, Monad}
import simulacrum.typeclass
import scala.annotation.implicitNotFound

@typeclass trait Pure[F[_]] {
@implicitNotFound("Could not find an instance of Pure for ${F}")
@typeclass trait Pure[F[_]] extends Serializable {
def pure[A](a: A): F[A]
}

Expand All @@ -22,4 +24,43 @@ object Pure {
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] = fm.flatMap(fa)(f)
def tailRecM[A, B](a: A)(f: (A) => F[Either[A, B]]): F[B] = fm.tailRecM(a)(f)
}

/****************************************************************************/
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */
/****************************************************************************/
/**
* Summon an instance of [[Pure]] for `F`.
*/
@inline def apply[F[_]](implicit instance: Pure[F]): Pure[F] = instance

trait Ops[F[_], A] {
type TypeClassType <: Pure[F]
def self: F[A]
val typeClassInstance: TypeClassType
}
trait AllOps[F[_], A] extends Ops[F, A]
trait ToPureOps {
implicit def toPureOps[F[_], A](target: F[A])(implicit tc: Pure[F]): Ops[F, A] {
type TypeClassType = Pure[F]
} = new Ops[F, A] {
type TypeClassType = Pure[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}
object nonInheritedOps extends ToPureOps
object ops {
implicit def toAllPureOps[F[_], A](target: F[A])(implicit tc: Pure[F]): AllOps[F, A] {
type TypeClassType = Pure[F]
} = new AllOps[F, A] {
type TypeClassType = Pure[F]
val self: F[A] = target
val typeClassInstance: TypeClassType = tc
}
}

/****************************************************************************/
/* END OF SIMULACRUM-MANAGED CODE */
/****************************************************************************/

}
Loading