Skip to content

Commit

Permalink
@nowarn deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed May 1, 2021
1 parent 71f397b commit 080a539
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions algebra-core/src/main/scala/algebra/instances/map.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package algebra
package instances

import scala.annotation.nowarn
import scala.collection.mutable

import algebra.ring._
Expand Down Expand Up @@ -52,6 +53,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))

@nowarn("msg=deprecated")
override def sum(as: TraversableOnce[Map[K, V]]): Map[K, V] = {
val acc = mutable.Map.empty[K, V]
as.foreach { m =>
Expand Down Expand Up @@ -95,6 +97,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)) }

@nowarn("msg=deprecated")
override def tryProduct(as: TraversableOnce[Map[K, V]]): Option[Map[K, V]] =
if (as.isEmpty) {
None
Expand Down
17 changes: 16 additions & 1 deletion algebra-core/src/main/scala/algebra/ring/Additive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package algebra
package ring

import scala.{specialized => sp}
import scala.annotation.tailrec
import scala.annotation.{nowarn, 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)
@nowarn("msg=deprecated")
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
}

Expand All @@ -31,13 +32,15 @@ trait AdditiveSemigroup[@sp(Int, Long, Float, Double) A] extends Any with Serial
*
* If the sequence is empty, returns None. Otherwise, returns Some(total).
*/
@nowarn("msg=deprecated")
def trySum(as: TraversableOnce[A]): Option[A] =
as.toIterator.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)
@nowarn("msg=deprecated")
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
}
}
Expand All @@ -46,7 +49,9 @@ trait AdditiveMonoid[@sp(Int, Long, Float, Double) A] extends Any with AdditiveS
override def additive: Monoid[A] = new Monoid[A] {
def empty = zero
def combine(x: A, y: A): A = plus(x, y)
@nowarn("msg=deprecated")
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
@nowarn("msg=deprecated")
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}

Expand All @@ -65,9 +70,11 @@ trait AdditiveMonoid[@sp(Int, Long, Float, Double) A] extends Any with AdditiveS
/**
* Given a sequence of `as`, compute the sum.
*/
@nowarn("msg=deprecated")
def sum(as: TraversableOnce[A]): A =
as.foldLeft(zero)(plus)

@nowarn("msg=deprecated")
override def trySum(as: TraversableOnce[A]): Option[A] =
if (as.isEmpty) None else Some(sum(as))
}
Expand All @@ -79,7 +86,9 @@ trait AdditiveCommutativeMonoid[@sp(Int, Long, Float, Double) A]
override def additive: CommutativeMonoid[A] = new CommutativeMonoid[A] {
def empty = zero
def combine(x: A, y: A): A = plus(x, y)
@nowarn("msg=deprecated")
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
@nowarn("msg=deprecated")
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}
}
Expand All @@ -90,7 +99,9 @@ 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)
@nowarn("msg=deprecated")
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
@nowarn("msg=deprecated")
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}

Expand All @@ -113,7 +124,9 @@ trait AdditiveCommutativeGroup[@sp(Int, Long, Float, Double) A]
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)
@nowarn("msg=deprecated")
override def combineAllOption(as: TraversableOnce[A]): Option[A] = trySum(as)
@nowarn("msg=deprecated")
override def combineAll(as: TraversableOnce[A]): A = sum(as)
}
}
Expand All @@ -129,6 +142,7 @@ 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)

@nowarn("msg=deprecated")
def trySum[A](as: TraversableOnce[A])(implicit ev: S[A]): Option[A] =
ev.trySum(as)
}
Expand All @@ -140,6 +154,7 @@ trait AdditiveMonoidFunctions[M[T] <: AdditiveMonoid[T]] extends AdditiveSemigro
def isZero[@sp(Int, Long, Float, Double) A](a: A)(implicit ev0: M[A], ev1: Eq[A]): Boolean =
ev0.isZero(a)

@nowarn("msg=deprecated")
def sum[@sp(Int, Long, Float, Double) A](as: TraversableOnce[A])(implicit ev: M[A]): A =
ev.sum(as)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package algebra
package ring

import scala.{specialized => sp}
import scala.annotation.tailrec
import scala.annotation.{nowarn, tailrec}

trait MultiplicativeSemigroup[@sp(Int, Long, Float, Double) A] extends Any with Serializable {
def multiplicative: Semigroup[A] =
Expand Down Expand Up @@ -31,6 +31,7 @@ trait MultiplicativeSemigroup[@sp(Int, Long, Float, Double) A] extends Any with
*
* If the sequence is empty, returns None. Otherwise, returns Some(total).
*/
@nowarn("msg=deprecated")
def tryProduct(as: TraversableOnce[A]): Option[A] =
as.toIterator.reduceOption(times)
}
Expand Down Expand Up @@ -62,9 +63,11 @@ trait MultiplicativeMonoid[@sp(Int, Long, Float, Double) A] extends Any with Mul
/**
* Given a sequence of `as`, compute the product.
*/
@nowarn("msg=deprecated")
def product(as: TraversableOnce[A]): A =
as.foldLeft(one)(times)

@nowarn("msg=deprecated")
override def tryProduct(as: TraversableOnce[A]): Option[A] =
if (as.isEmpty) None else Some(product(as))
}
Expand Down Expand Up @@ -118,6 +121,7 @@ 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)

@nowarn("msg=deprecated")
def tryProduct[A](as: TraversableOnce[A])(implicit ev: S[A]): Option[A] =
ev.tryProduct(as)
}
Expand All @@ -129,6 +133,7 @@ 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)

@nowarn("msg=deprecated")
def product[@sp(Int, Long, Float, Double) A](as: TraversableOnce[A])(implicit ev: M[A]): A =
ev.product(as)
}
Expand Down

0 comments on commit 080a539

Please sign in to comment.