Permalink
Browse files

support scala-js

  • Loading branch information...
xuwei-k committed Feb 25, 2016
1 parent 7c15ea2 commit d63dcaeeb444ef4e2609df5b181326a12d5d5fcb
Showing with 706 additions and 452 deletions.
  1. +7 −6 .travis.yml
  2. +9 −0 core/js/src/main/scala/scalaz/std/FutureInstances.scala
  3. +5 −0 core/js/src/main/scala/scalaz/std/java/TimeInstances0.scala
  4. +17 −0 core/jvm/src/main/scala/scalaz/std/FutureInstances.scala
  5. +27 −0 core/jvm/src/main/scala/scalaz/std/java/TimeInstances0.scala
  6. +1 −14 core/src/main/scala/scalaz/std/Future.scala
  7. +2 −15 core/src/main/scala/scalaz/std/java/time.scala
  8. +154 −58 project/build.scala
  9. +2 −0 project/plugins.sbt
  10. +6 −0 scalacheck-binding/js/src/main/scala/scalaz/scalacheck/ScalazArbitraryPlatform.scala
  11. +19 −0 scalacheck-binding/jvm/src/main/scala/scalaz/scalacheck/ScalazArbitraryPlatform.scala
  12. +1 −9 scalacheck-binding/src/main/scala/scalaz/scalacheck/ScalazArbitrary.scala
  13. +223 −194 scalacheck-binding/src/main/scala/scalaz/scalacheck/ScalazProperties.scala
  14. +5 −0 tests/js/src/test/scala/scalaz/SpecLitePlatform.scala
  15. +11 −0 tests/jvm/src/test/scala/scalaz/EphemeralStreamTestJVM.scala
  16. +25 −0 tests/jvm/src/test/scala/scalaz/NeedTestJVM.scala
  17. +22 −0 tests/jvm/src/test/scala/scalaz/NonEmptyListTestJVM.scala
  18. 0 tests/{ → jvm}/src/test/scala/scalaz/SI7932Test.scala
  19. +11 −0 tests/jvm/src/test/scala/scalaz/SpecLitePlatform.scala
  20. +36 −0 tests/jvm/src/test/scala/scalaz/TraverseTestJVM.scala
  21. +14 −0 tests/jvm/src/test/scala/scalaz/TreeLocTestJVM.scala
  22. +21 −0 tests/jvm/src/test/scala/scalaz/TreeTestJVM.scala
  23. 0 tests/{ → jvm}/src/test/scala/scalaz/concurrent/ActorTest.scala
  24. 0 tests/{ → jvm}/src/test/scala/scalaz/concurrent/ConcurrentTaskTest.scala
  25. 0 tests/{ → jvm}/src/test/scala/scalaz/concurrent/ConcurrentTest.scala
  26. 0 tests/{ → jvm}/src/test/scala/scalaz/concurrent/FutureTest.scala
  27. 0 tests/{ → jvm}/src/test/scala/scalaz/concurrent/MVarTest.scala
  28. 0 tests/{ → jvm}/src/test/scala/scalaz/concurrent/TaskTest.scala
  29. 0 tests/{ → jvm}/src/test/scala/scalaz/concurrent/TimerTest.scala
  30. 0 tests/{ → jvm}/src/test/scala/scalaz/std/FutureTest.scala
  31. +68 −0 tests/jvm/src/test/scala/scalaz/std/java/TimeTestJVM.scala
  32. +0 −6 tests/src/test/scala/scalaz/EphemeralStreamTest.scala
  33. +8 −7 tests/src/test/scala/scalaz/FoldableTest.scala
  34. +0 −21 tests/src/test/scala/scalaz/NeedTest.scala
  35. +0 −14 tests/src/test/scala/scalaz/NonEmptyListTest.scala
  36. +10 −15 tests/src/test/scala/scalaz/SpecLite.scala
  37. +0 −23 tests/src/test/scala/scalaz/TraverseTest.scala
  38. +0 −7 tests/src/test/scala/scalaz/TreeLocTest.scala
  39. +0 −12 tests/src/test/scala/scalaz/TreeTest.scala
  40. +2 −51 tests/src/test/scala/scalaz/std/java/TimeTest.scala
View
@@ -19,22 +19,23 @@ cache:
language: scala
scala:
- 2.12.0-M3
- 2.11.7
- 2.10.6
jdk:
- oraclejdk8 # scalaz 7.3 does not support Java 7
script:
- sbt ++$TRAVIS_SCALA_VERSION -J-Xmx3784m check-gen-type-classes test
- sbt ++$TRAVIS_SCALA_VERSION -J-Xmx3784m check-gen-type-classes "project $TEST_PROJECT" test:compile
- sbt ++$TRAVIS_SCALA_VERSION "project $TEST_PROJECT" test "project /" publishLocal
# Tricks to avoid unnecessary cache updates
- find $HOME/.sbt -name "*.lock" | xargs rm
- find $HOME/.ivy2 -name "ivydata-*.properties" | xargs rm
matrix:
include:
- scala: 2.12.0-M3
jdk: oraclejdk8
env:
matrix:
- TEST_PROJECT="rootJVM"
- TEST_PROJECT="rootJS"
addons:
apt:
@@ -0,0 +1,9 @@
package scalaz
package std
import scala.concurrent.{ExecutionContext, Future}
trait FutureInstances extends FutureInstances1 {
implicit def futureMonoid[A](implicit g: Monoid[A], ec: ExecutionContext): Monoid[Future[A]] =
Monoid.liftMonoid[Future, A]
}
@@ -0,0 +1,5 @@
package scalaz
package std.java
trait TimeInstances0 {
}
@@ -0,0 +1,17 @@
package scalaz
package std
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration.Duration
trait FutureInstances extends FutureInstances1 {
/**
* Requires explicit usage as the use of `Await.result`. Can throw an exception, which is inherently bad.
*/
def futureComonad(duration: Duration)(implicit executionContext: ExecutionContext): Comonad[Future] = new FutureInstance with Comonad[Future] {
def copoint[A](f: Future[A]): A = Await.result(f, duration)
}
implicit def futureMonoid[A](implicit g: Monoid[A], ec: ExecutionContext): Monoid[Future[A]] =
Monoid.liftMonoid[Future, A]
}
@@ -0,0 +1,27 @@
package scalaz
package std.java
import java.time._
trait TimeInstances0 {
private[this] def orderFromInt[A](f: (A, A) => Int): Order[A] = new Order[A] {
def order(x: A, y: A) = Ordering.fromInt(f(x, y))
}
implicit val instantInstance: Order[Instant] = orderFromInt[Instant](_ compareTo _)
implicit val localDateTimeInstance: Order[LocalDateTime] = orderFromInt[LocalDateTime](_ compareTo _)
implicit val offsetDateTimeInstance: Order[OffsetDateTime] = orderFromInt[OffsetDateTime](_ compareTo _)
implicit val offsetTimeInstance: Order[OffsetTime] = orderFromInt[OffsetTime](_ compareTo _)
implicit val zonedDateTime: Order[ZonedDateTime] = orderFromInt[ZonedDateTime](_ compareTo _)
implicit val zoneOffsetInstance: Order[ZoneOffset] = orderFromInt[ZoneOffset](_ compareTo _)
implicit val dayOfWeekInstance: Enum[DayOfWeek] = new Enum[DayOfWeek] {
override val max = Some(DayOfWeek.SUNDAY)
override val min = Some(DayOfWeek.MONDAY)
override def pred(a: DayOfWeek) = a.minus(1)
override def succ(a: DayOfWeek) = a.plus(1)
override def order(x: DayOfWeek, y: DayOfWeek) =
Ordering.fromInt(x compareTo y)
}
}
@@ -3,8 +3,7 @@ package std
import _root_.java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.{ Try, Success => TSuccess }
trait FutureInstances1 {
@@ -15,18 +14,6 @@ trait FutureInstances1 {
Semigroup.liftSemigroup[Future, A]
}
trait FutureInstances extends FutureInstances1 {
/**
* Requires explicit usage as the use of `Await.result`. Can throw an exception, which is inherently bad.
*/
def futureComonad(duration: Duration)(implicit executionContext: ExecutionContext): Comonad[Future] = new FutureInstance with Comonad[Future] {
def copoint[A](f: Future[A]): A = Await.result(f, duration)
}
implicit def futureMonoid[A](implicit g: Monoid[A], ec: ExecutionContext): Monoid[Future[A]] =
Monoid.liftMonoid[Future, A]
}
private class FutureInstance(implicit ec: ExecutionContext) extends Nondeterminism[Future] with Cobind[Future] with MonadError[Future, Throwable] with Catchable[Future] {
def point[A](a: => A): Future[A] = Future(a)
def bind[A, B](fa: Future[A])(f: A => Future[B]): Future[B] = fa flatMap f
@@ -3,7 +3,8 @@ package std.java
import java.time._
trait TimeInstances {
// https://github.com/scala-js/scala-js-java-time/issues/7
trait TimeInstances extends TimeInstances0 {
private[this] def orderFromInt[A](f: (A, A) => Int): Order[A] = new Order[A] {
def order(x: A, y: A) = Ordering.fromInt(f(x, y))
@@ -31,13 +32,7 @@ trait TimeInstances {
}
implicit val monthDayInstance: Order[MonthDay] = orderFromInt[MonthDay](_ compareTo _)
implicit val instantInstance: Order[Instant] = orderFromInt[Instant](_ compareTo _)
implicit val localTimeInstance: Order[LocalTime] = orderFromInt[LocalTime](_ compareTo _)
implicit val localDateTimeInstance: Order[LocalDateTime] = orderFromInt[LocalDateTime](_ compareTo _)
implicit val offsetDateTimeInstance: Order[OffsetDateTime] = orderFromInt[OffsetDateTime](_ compareTo _)
implicit val offsetTimeInstance: Order[OffsetTime] = orderFromInt[OffsetTime](_ compareTo _)
implicit val zonedDateTime: Order[ZonedDateTime] = orderFromInt[ZonedDateTime](_ compareTo _)
implicit val zoneOffsetInstance: Order[ZoneOffset] = orderFromInt[ZoneOffset](_ compareTo _)
implicit val yearInstance: Enum[Year] = new Enum[Year] {
override def pred(a: Year) = a.minusYears(1)
@@ -62,14 +57,6 @@ trait TimeInstances {
Ordering.fromInt(x compareTo y)
}
implicit val dayOfWeekInstance: Enum[DayOfWeek] = new Enum[DayOfWeek] {
override val max = Some(DayOfWeek.SUNDAY)
override val min = Some(DayOfWeek.MONDAY)
override def pred(a: DayOfWeek) = a.minus(1)
override def succ(a: DayOfWeek) = a.plus(1)
override def order(x: DayOfWeek, y: DayOfWeek) =
Ordering.fromInt(x compareTo y)
}
}
object time extends TimeInstances
Oops, something went wrong.

0 comments on commit d63dcae

Please sign in to comment.