Skip to content

Commit

Permalink
fixes typelevel#219 - publish for Scala 2.13.0-M5
Browse files Browse the repository at this point in the history
  • Loading branch information
erikerlandson committed Nov 29, 2018
1 parent f5f6a96 commit 9ab2937
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 42 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ sudo: false
language: scala

scala:
- 2.11.11
- 2.10.6
- 2.11.12
- 2.12.4
- 2.13.0-M5

env:
- DEPLOY=false
Expand All @@ -14,7 +15,7 @@ jdk:

matrix:
include:
- scala: 2.12.3
- scala: 2.12.4
jdk: oraclejdk8
env: DEPLOY=true

Expand Down
27 changes: 16 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ import sbtrelease.Utilities._
import ReleaseTransformations._
import microsites.ExtraMdFileConfig

lazy val scalaCheckVersion = "1.13.5"
lazy val scalaTestVersion = "3.0.4"
lazy val disciplineVersion = "0.8"
lazy val catsVersion = "1.0.1"
def preScala2_13(scalaVersion: String): Boolean =
CrossVersion.partialVersion(scalaVersion) match {
case Some((major, _)) if major < 2 => true
case Some((2, minor)) if minor < 13 => true
case _ => false
}

lazy val scalaCheckVersion = "1.14.0"
lazy val scalaTestVersion = "3.0.6-SNAP5"
lazy val catsVersion = "1.5.0-RC0"
lazy val catalystsVersion = "0.0.5"

def disciplineVersion(scalaVersion: String): String
= if (preScala2_13(scalaVersion)) "0.9" else "0.10"

lazy val buildSettings = Seq(
organization := "org.typelevel",
scalaVersion := "2.12.4",
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.12.4")
crossScalaVersions := Seq("2.11.12", "2.12.4", "2.13.0-M5")
)

lazy val commonSettings = Seq(
Expand All @@ -25,15 +34,11 @@ lazy val commonSettings = Seq(
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
//"-Ywarn-value-discard", // fails with @sp on Unit
"-Xfuture"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) => Seq.empty
case _ => Seq("-Ywarn-unused-import")
}),
) ++ (if (preScala2_13(scalaVersion.value)) Seq("-Yno-adapted-args") else Seq.empty),
resolvers += Resolver.sonatypeRepo("public"),
scalacOptions in (Compile, console) ~= (_ filterNot (_ == "-Ywarn-unused-import")),
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value,
Expand Down Expand Up @@ -140,7 +145,7 @@ lazy val laws = crossProject
.settings(libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-kernel-laws" % catsVersion,
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
"org.typelevel" %%% "discipline" % disciplineVersion,
"org.typelevel" %%% "discipline" % disciplineVersion(scalaVersion.value),
"org.typelevel" %%% "catalysts-platform" % catalystsVersion % "test",
"org.typelevel" %%% "catalysts-macros" % catalystsVersion % "test",
"org.scalatest" %%% "scalatest" % scalaTestVersion % "test"))
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/algebra/instances/map.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MapAdditiveMonoid[K, V](implicit V: AdditiveSemigroup[V]) extends Additive
else if (n == 0) zero
else throw new IllegalArgumentException("Illegal negative exponent to sumN: %s" format n)

override def sum(as: TraversableOnce[Map[K, V]]): Map[K, V] = {
override def sum(as: Iterator[Map[K, V]]): Map[K, V] = {
val acc = mutable.Map.empty[K, V]
as.foreach { m =>
val it = m.iterator
Expand Down Expand Up @@ -93,7 +93,7 @@ class MapSemiring[K, V](implicit V: Semiring[V]) extends MapAdditiveMonoid[K, V]
else if (n == 1) x
else x.map { case (k, v) => (k, V.pow(v, n)) }

override def tryProduct(as: TraversableOnce[Map[K, V]]): Option[Map[K, V]] =
override def tryProduct(as: Iterator[Map[K, V]]): Option[Map[K, V]] =
if (as.isEmpty) {
None
} else {
Expand Down
39 changes: 23 additions & 16 deletions core/src/main/scala/algebra/ring/Additive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import scala.annotation.tailrec
trait AdditiveSemigroup[@sp(Int, Long, Float, Double) A] extends Any with Serializable {
def additive: Semigroup[A] = new Semigroup[A] {
def combine(x: A, y: A): A = plus(x, y)
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
}

def plus(x: A, y: A): A
Expand All @@ -30,23 +29,23 @@ trait AdditiveSemigroup[@sp(Int, Long, Float, Double) A] extends Any with Serial
*
* If the sequence is empty, returns None. Otherwise, returns Some(total).
*/
def trySum(as: TraversableOnce[A]): Option[A] =
def trySum(as: Iterable[A]): Option[A] = // this one should not need to be overridden
trySum(as.iterator)

def trySum(as: Iterator[A]): Option[A] = // override this one in sub-classes
as.reduceOption(plus)
}

trait AdditiveCommutativeSemigroup[@sp(Int, Long, Float, Double) A] extends Any with AdditiveSemigroup[A] {
override def additive: CommutativeSemigroup[A] = new CommutativeSemigroup[A] {
def combine(x: A, y: A): A = plus(x, y)
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
}
}

trait AdditiveMonoid[@sp(Int, Long, Float, Double) A] extends Any with AdditiveSemigroup[A] {
override def additive: Monoid[A] = new Monoid[A] {
def empty = zero
def combine(x: A, y: A): A = plus(x, y)
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}

def zero: A
Expand All @@ -64,19 +63,25 @@ trait AdditiveMonoid[@sp(Int, Long, Float, Double) A] extends Any with AdditiveS
/**
* Given a sequence of `as`, compute the sum.
*/
def sum(as: TraversableOnce[A]): A =
as.foldLeft(zero)(plus)
def sum(as: Iterable[A]): A =
sum(as.iterator)

def sum(as: Iterator[A]): A = {
var s = zero
while (as.hasNext) {
s = plus(s, as.next)
}
s
}

override def trySum(as: TraversableOnce[A]): Option[A] =
override def trySum(as: Iterator[A]): Option[A] =
if (as.isEmpty) None else Some(sum(as))
}

trait AdditiveCommutativeMonoid[@sp(Int, Long, Float, Double) A] extends Any with AdditiveMonoid[A] with AdditiveCommutativeSemigroup[A] {
override def additive: CommutativeMonoid[A] = new CommutativeMonoid[A] {
def empty = zero
def combine(x: A, y: A): A = plus(x, y)
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}
}

Expand All @@ -86,8 +91,6 @@ trait AdditiveGroup[@sp(Int, Long, Float, Double) A] extends Any with AdditiveMo
def combine(x: A, y: A): A = plus(x, y)
override def remove(x: A, y: A): A = minus(x, y)
def inverse(x: A): A = negate(x)
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}

def negate(x: A): A
Expand All @@ -106,8 +109,6 @@ trait AdditiveCommutativeGroup[@sp(Int, Long, Float, Double) A] extends Any with
def combine(x: A, y: A): A = plus(x, y)
override def remove(x: A, y: A): A = minus(x, y)
def inverse(x: A): A = negate(x)
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}
}

Expand All @@ -122,7 +123,10 @@ trait AdditiveSemigroupFunctions[S[T] <: AdditiveSemigroup[T]] {
def sumN[@sp(Int, Long, Float, Double) A](a: A, n: Int)(implicit ev: S[A]): A =
ev.sumN(a, n)

def trySum[A](as: TraversableOnce[A])(implicit ev: S[A]): Option[A] =
def trySum[A](as: Iterable[A])(implicit ev: S[A]): Option[A] =
ev.trySum(as)

def trySum[A](as: Iterator[A])(implicit ev: S[A]): Option[A] =
ev.trySum(as)
}

Expand All @@ -133,7 +137,10 @@ trait AdditiveMonoidFunctions[M[T] <: AdditiveMonoid[T]] extends AdditiveSemigr
def isZero[@sp(Int, Long, Float, Double) A](a: A)(implicit ev0: M[A], ev1: Eq[A]): Boolean =
ev0.isZero(a)

def sum[@sp(Int, Long, Float, Double) A](as: TraversableOnce[A])(implicit ev: M[A]): A =
def sum[@sp(Int, Long, Float, Double) A](as: Iterable[A])(implicit ev: M[A]): A =
ev.sum(as)

def sum[@sp(Int, Long, Float, Double) A](as: Iterator[A])(implicit ev: M[A]): A =
ev.sum(as)
}

Expand Down
29 changes: 23 additions & 6 deletions core/src/main/scala/algebra/ring/Multiplicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ trait MultiplicativeSemigroup[@sp(Int, Long, Float, Double) A] extends Any with
*
* If the sequence is empty, returns None. Otherwise, returns Some(total).
*/
def tryProduct(as: TraversableOnce[A]): Option[A] =
def tryProduct(as: Iterable[A]): Option[A] = // should not need to be overridden
tryProduct(as.iterator)

def tryProduct(as: Iterator[A]): Option[A] = // override this one in subclasses
as.reduceOption(times)
}

Expand Down Expand Up @@ -61,10 +64,18 @@ trait MultiplicativeMonoid[@sp(Int, Long, Float, Double) A] extends Any with Mul
/**
* Given a sequence of `as`, compute the product.
*/
def product(as: TraversableOnce[A]): A =
as.foldLeft(one)(times)
def product(as: Iterable[A]): A =
product(as.iterator)

def product(as: Iterator[A]): A = {
var p = one
while (as.hasNext) {
p = times(p, as.next)
}
p
}

override def tryProduct(as: TraversableOnce[A]): Option[A] =
override def tryProduct(as: Iterator[A]): Option[A] =
if (as.isEmpty) None else Some(product(as))
}

Expand Down Expand Up @@ -111,7 +122,10 @@ trait MultiplicativeSemigroupFunctions[S[T] <: MultiplicativeSemigroup[T]] {
def pow[@sp(Int, Long, Float, Double) A](a: A, n: Int)(implicit ev: S[A]): A =
ev.pow(a, n)

def tryProduct[A](as: TraversableOnce[A])(implicit ev: S[A]): Option[A] =
def tryProduct[A](as: Iterable[A])(implicit ev: S[A]): Option[A] =
ev.tryProduct(as)

def tryProduct[A](as: Iterator[A])(implicit ev: S[A]): Option[A] =
ev.tryProduct(as)
}

Expand All @@ -122,7 +136,10 @@ trait MultiplicativeMonoidFunctions[M[T] <: MultiplicativeMonoid[T]] extends Mul
def isOne[@sp(Int, Long, Float, Double) A](a: A)(implicit ev0: M[A], ev1: Eq[A]): Boolean =
ev0.isOne(a)

def product[@sp(Int, Long, Float, Double) A](as: TraversableOnce[A])(implicit ev: M[A]): A =
def product[@sp(Int, Long, Float, Double) A](as: Iterable[A])(implicit ev: M[A]): A =
ev.product(as)

def product[@sp(Int, Long, Float, Double) A](as: Iterator[A])(implicit ev: M[A]): A =
ev.product(as)
}

Expand Down
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.1")
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.16")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.2")
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.7.27")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.7")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.22")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.25")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.18")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0-M5")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.3")

0 comments on commit 9ab2937

Please sign in to comment.