All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fif.ops.Sum.scala Maven / Gradle / Ivy

The newest version!
package fif.ops

import fif.Data

import scala.language.higherKinds
import scala.reflect.ClassTag

object Sum extends Serializable {

  import Data.ops._

  def apply[N: Numeric: ClassTag, D[_]: Data](data: D[N]): N = {
    val add = implicitly[Numeric[N]].plus _
    data.aggregate(implicitly[Numeric[N]].zero)(add, add)
  }

  def apply[N: Numeric](first: N, numbers: N*): N = {
    val add = implicitly[Numeric[N]].plus _
    numbers.foldLeft(first)(add)
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy