Created
March 27, 2012 16:17
-
-
Save soc/2217615 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
| 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