-
Notifications
You must be signed in to change notification settings - Fork 14
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
Initial support for export-hook #22
Changes from 5 commits
d46e716
17fd314
c8cd485
ccb4693
5feb09a
3a29c53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,22 @@ addCommandAlias("gitSnapshots", ";set version in ThisBuild := git.gitDescribedVe | |
val gh = GitHubSettings(org = "non", proj = "alleycats", publishOrg = "org.typelevel", license = mit) | ||
val devs = Seq(Dev("Erik Osheim", "non")) | ||
|
||
val vers = typelevel.versions ++ alleycats.versions | ||
val updates = Map( | ||
"macro-compat" -> "1.1.0", | ||
"export-hook" -> "1.1.0", | ||
"simulacrum" -> "0.5.0" | ||
) | ||
val updatesSettings = Seq( resolvers += Resolver.sonatypeRepo("snapshots")) | ||
|
||
val vers = typelevel.versions ++ alleycats.versions ++ updates | ||
val libs = typelevel.libraries ++ alleycats.libraries | ||
val addins = typelevel.scalacPlugins ++ alleycats.scalacPlugins | ||
val vAll = Versions(vers, libs, addins) | ||
|
||
/** | ||
* alleycats - This is the root project that aggregates the alleycatsJVM and alleycatsJS sub projects | ||
*/ | ||
lazy val rootSettings = buildSettings ++ commonSettings ++ publishSettings ++ scoverageSettings | ||
lazy val rootSettings = buildSettings ++ commonSettings ++ publishSettings ++ scoverageSettings ++ updatesSettings | ||
|
||
lazy val module = mkModuleFactory(gh.proj, mkConfig(rootSettings, commonJvmSettings, commonJsSettings)) | ||
lazy val prj = mkPrjFactory(rootSettings) | ||
|
@@ -51,7 +58,7 @@ lazy val coreJVM = coreM.jvm | |
lazy val coreJS = coreM.js | ||
lazy val coreM = module("core", CrossType.Pure) | ||
.settings(typelevel.macroCompatSettings(vAll):_*) | ||
.settings(addLibs(vAll, "cats-core"):_*) | ||
.settings(addLibs(vAll, "cats-core", "export-hook", "simulacrum"):_*) | ||
|
||
/** | ||
* Laws project | ||
|
@@ -86,7 +93,7 @@ lazy val commonSettings = sharedCommonSettings ++ | |
addCompilerPlugins(vAll, "kind-projector") ++ Seq( | ||
scalacOptions ++= scalacAllOptions, | ||
parallelExecution in Test := false | ||
) ++ warnUnusedImport ++ unidocCommonSettings | ||
) /* ++ warnUnusedImport */ ++ unidocCommonSettings // spurious warnings from macro annotations expected | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small point (again): locally this works for me enabled, perhaps worth re-adding? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! Interesting ... I'll try that again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still seeing the unused import warnings :-( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for this, so am I :-( |
||
|
||
lazy val commonJsSettings = Seq( | ||
scalaJSStage in Global := FastOptStage | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package alleycats | ||
|
||
import cats.SemigroupK | ||
import export.imports | ||
import simulacrum.typeclass | ||
|
||
@typeclass trait ConsK[F[_]] { | ||
def cons[A](hd: A, tl: F[A]): F[A] | ||
} | ||
|
||
object ConsK extends ConsK0 { | ||
implicit def pureSemigroupKIsConsK[F[_]](implicit p: Pure[F], s: SemigroupK[F]): ConsK[F] = | ||
new ConsK[F] { | ||
def cons[A](hd: A, tl: F[A]): F[A] = s.combine(p.pure(hd), tl) | ||
} | ||
} | ||
|
||
@imports[ConsK] | ||
trait ConsK0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment applies to various other places in this PR as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My default position is that all pure code should be public unless there's a compelling reason to the contrary. I don't think there is here, so I wouldn't make this private as a matter of course. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a huge scala infrastructure at work, so fighting binary incompatibilities in library versions is usually my compelling reason to not expose something that is kind of an internal detail :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that there's a discussion to be had here which goes beyond the scope of this PR. Specifically though, I don't see any binary incompatibility issues arising from this trait. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
package alleycats | ||
|
||
import cats.{Applicative, CoflatMap, Comonad} | ||
import export.imports | ||
import simulacrum.typeclass | ||
|
||
@typeclass trait Extract[F[_]] { | ||
def extract[A](fa: F[A]): A | ||
} | ||
|
||
object Extract { | ||
object Extract extends Extract0 { | ||
// Ideally this would be an exported subclass instance provided by Comonad | ||
implicit def comonadIsExtract[F[_]](implicit ev: Comonad[F]): Extract[F] = | ||
new Extract[F] { | ||
def extract[A](fa: F[A]): A = ev.extract(fa) | ||
} | ||
|
||
// Ideally this would be an instance exported to Comonad | ||
implicit def extractCoflatMapIsComonad[F[_]](implicit e: Extract[F], cf: CoflatMap[F]): Comonad[F] = | ||
new Comonad[F] { | ||
def extract[A](fa: F[A]): A = e.extract(fa) | ||
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) | ||
} | ||
} | ||
|
||
@imports[Extract] | ||
trait Extract0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
package alleycats | ||
|
||
import cats.{Applicative, FlatMap, Monad} | ||
import export.imports | ||
import simulacrum.typeclass | ||
|
||
@typeclass trait Pure[F[_]] { | ||
def pure[A](a: A): F[A] | ||
} | ||
|
||
object Pure { | ||
object Pure extends Pure0 { | ||
// Ideally this would be an exported subclass instance provided by Applicative | ||
implicit def applicativeIsPure[F[_]](implicit ev: Applicative[F]): Pure[F] = | ||
new Pure[F] { | ||
def pure[A](a: A): F[A] = ev.pure(a) | ||
} | ||
|
||
// Ideally this would be an instance exported to Monad | ||
implicit def pureFlatMapIsMonad[F[_]](implicit p: Pure[F], fm: FlatMap[F]): Monad[F] = | ||
new Monad[F] { | ||
def pure[A](a: A): F[A] = p.pure(a) | ||
override def map[A, B](fa: F[A])(f: A => B): F[B] = fm.map(fa)(f) | ||
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B] = fm.flatMap(fa)(f) | ||
} | ||
} | ||
|
||
@imports[Pure] | ||
trait Pure0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package alleycats.std | ||
package alleycats | ||
package std | ||
|
||
object all | ||
extends ListInstances | ||
with OptionInstances | ||
with SetInstances | ||
with TryInstances | ||
import export._ | ||
|
||
@reexports( | ||
EmptyKInstances, | ||
ListInstances, | ||
OptionInstances, | ||
SetInstances, | ||
TryInstances | ||
) object all extends LegacySetInstances with LegacyTryInstances |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
package alleycats | ||
package std | ||
|
||
object list extends ListInstances | ||
import export._ | ||
|
||
trait ListInstances { | ||
implicit val listEmptyK: EmptyK[List] = | ||
@reexports(ListInstances) | ||
object list | ||
|
||
@exports | ||
object ListInstances { | ||
@export(Orphan) | ||
implicit val exportListEmptyK: EmptyK[List] = | ||
new EmptyK[List] { | ||
def empty[A]: List[A] = Nil | ||
} | ||
|
||
@export(Orphan) | ||
implicit val exportListConsK: ConsK[List] = | ||
new ConsK[List] { | ||
def cons[A](hd: A, tl: List[A]): List[A] = hd :: tl | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small point; As you now have no shapshot dependendencies, might we an idea to remove/comment out this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.