Skip to content

Instantly share code, notes, and snippets.

@soc
Created March 27, 2012 16:17
Show Gist options
  • Select an option

  • Save soc/2217615 to your computer and use it in GitHub Desktop.

Select an option

Save soc/2217615 to your computer and use it in GitHub Desktop.
abstract class NumericRange[T]
(val start: T, val end: T, val step: T, val isInclusive: Boolean)
(implicit num: Integral[T])
extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
final override def sum[B >: T](implicit num: Numeric[B]): B = {
import num.Ops
if (isEmpty) this.num fromInt 0
else if (numRangeElements == 1) head
else ((this.num fromInt numRangeElements) * (head + last) / (this.num fromInt 2))
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment