-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Introduce cats-jvm and cats-js. #507
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0c3b1a5
Introduce cats-jvm and cats-js.
non 620b33b
Re-enable fatal warnings, except in the macros project.
non 1f436a9
Use scala-bricks to extract platform-specific code.
non ab7171f
Bump sbt-scalajs to 0.6.5.
non 01b0624
Merge remote-tracking branch 'origin/master' into topic/js-jvm-projs
non 90a3a2d
Move Bimonad-related files to correct locations.
non 2407a24
Move to non-snapshot version of scala-bricks dependency.
non f04cfbc
Merge remote-tracking branch 'origin/master' into topic/js-jvm-projs
non File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cats | ||
package jvm | ||
package std | ||
|
||
import scala.concurrent.{Await, ExecutionContext, Future} | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
import cats.std.FutureCoflatMap | ||
import cats.syntax.all._ | ||
|
||
object future { | ||
|
||
type E = ExecutionContext | ||
|
||
def futureEq[A: Eq](atMost: FiniteDuration)(implicit ec: E): Eq[Future[A]] = | ||
new Eq[Future[A]] { | ||
def eqv(x: Future[A], y: Future[A]): Boolean = | ||
Await.result((x zip y).map { case (x, y) => x === y }, atMost) | ||
} | ||
|
||
def futurePartialOrder[A: PartialOrder](atMost: FiniteDuration)(implicit ec: E): PartialOrder[Future[A]] = | ||
new PartialOrder[Future[A]] { | ||
def partialCompare(x: Future[A], y: Future[A]): Double = | ||
Await.result((x zip y).map { case (x, y) => x partialCompare y }, atMost) | ||
} | ||
|
||
def futureOrder[A: Order](atMost: FiniteDuration)(implicit ec: E): Eq[Future[A]] = | ||
new Order[Future[A]] { | ||
def compare(x: Future[A], y: Future[A]): Int = | ||
Await.result((x zip y).map { case (x, y) => x compare y }, atMost) | ||
} | ||
|
||
def futureComonad(atMost: FiniteDuration)(implicit ec: E): Comonad[Future] = | ||
new FutureCoflatMap with Comonad[Future] { | ||
def extract[A](x: Future[A]): A = | ||
Await.result(x, atMost) | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...c/test/scala/cats/tests/FutureTests.scala → ...c/test/scala/cats/tests/FutureTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
laws/shared/src/main/scala/cats/laws/SerializableLaws.scala
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cats | ||
package laws | ||
|
||
import org.scalacheck.Prop | ||
import org.scalacheck.Prop.{ False, Proof, Result } | ||
|
||
/** | ||
* Check for Java Serializability. | ||
* | ||
* This laws is only applicative on the JVM, but is something we want | ||
* to be sure to enforce. Therefore, we use cats.macros.Platform to do | ||
* a runtime check rather than create a separate jvm-laws project. | ||
*/ | ||
object SerializableLaws { | ||
|
||
// This part is a bit tricky. Basically, we only want to test | ||
// serializability on the JVM. | ||
// | ||
// The Platform.isJs macro will give us a literal true or false at | ||
// compile time, so we rely on scalac to prune away the "other" | ||
// branch. Thus, when scala.js look at this method it won't "see" | ||
// the branch which was removed, and will avoid an error trying to | ||
// suport java.io.*. | ||
// | ||
// This ends up being a lot nicer than having to split the entire | ||
// laws project. | ||
|
||
def serializable[A](a: A): Prop = | ||
if (cats.macros.Platform.isJs) Prop(_ => Result(status = Proof)) else Prop { _ => | ||
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream } | ||
|
||
val baos = new ByteArrayOutputStream() | ||
val oos = new ObjectOutputStream(baos) | ||
var ois: ObjectInputStream = null | ||
try { | ||
oos.writeObject(a) | ||
oos.close() | ||
val bais = new ByteArrayInputStream(baos.toByteArray()) | ||
ois = new ObjectInputStream(bais) | ||
val a2 = ois.readObject() | ||
ois.close() | ||
Result(status = Proof) | ||
} catch { case _: Throwable => | ||
Result(status = False) | ||
} finally { | ||
oos.close() | ||
if (ois != null) ois.close() | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cats.macros | ||
|
||
import scala.reflect.macros.Context | ||
|
||
object Platform { | ||
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. clever :-) |
||
|
||
final def isJvm: Boolean = macro isJvmImpl | ||
|
||
final def isJs: Boolean = macro isJsImpl | ||
|
||
def isJvmImpl(c: Context): c.Expr[Boolean] = { | ||
import c.universe._ | ||
c.Expr(Literal(Constant(false))) | ||
} | ||
|
||
def isJsImpl(c: Context): c.Expr[Boolean] = { | ||
import c.universe._ | ||
c.Expr(Literal(Constant(true))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cats.macros | ||
|
||
import scala.reflect.macros.Context | ||
|
||
object Platform { | ||
def isJvm: Boolean = macro isJvmImpl | ||
def isJs: Boolean = macro isJsImpl | ||
|
||
def isJvmImpl(c: Context): c.Expr[Boolean] = { | ||
import c.universe._ | ||
c.Expr(Literal(Constant(true))) | ||
} | ||
|
||
def isJsImpl(c: Context): c.Expr[Boolean] = { | ||
import c.universe._ | ||
c.Expr(Literal(Constant(false))) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is something necessitating this?
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.
Yes, this is necessary for now for
cats-macros
due to differences between 2.10 and 2.11. I think I can fix this though so I'll re-enable it when I do.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.
If you won't be fixing it in this PR, what about omitting this option from only the macros module?