Created
October 21, 2016 06:58
-
-
Save macalinao/0b4e4b9a237eade35741a10bdcb1e8d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def divideScalars[S, T]( | |
divisors: Map[Int, S], scalars: Map[Int, T] | |
)(implicit s: scala.math.Numeric[S], t: scala.math.Numeric[T]): Map[Int, Double] = { | |
val df = divisors.mapValues(x => s.toDouble(x)) | |
scalars.mapValues(x => t.toDouble(x)).transform((k, v) => | |
df.get(k) match { | |
case Some(divisor) if divisor != 0 => v / divisor | |
case None => 0 | |
} | |
) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment