Skip to content

Commit 235b6a0

Browse files
committed
LengthType: make it be a custom value class.
1 parent 5244c5c commit 235b6a0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/strawman/collections/CollectionStrawMan2.scala

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package strawman.collections
22

33
import Predef.{augmentString => _, wrapString => _, _}
4+
import scala.language.implicitConversions
45
import scala.reflect.ClassTag
56

67
/** A strawman architecture for new collections. It contains some
@@ -13,7 +14,17 @@ import scala.reflect.ClassTag
1314
*/
1415
object CollectionStrawMan1 {
1516

16-
type LengthType = Long
17+
type LengthTypeUnderlying = Long
18+
19+
final case class LengthType(u: LengthTypeUnderlying) extends AnyVal {
20+
def +(other: LengthType) = LengthType(u + other.u)
21+
def -(other: LengthType) = LengthType(u - other.u)
22+
def /(other: LengthType) = LengthType(u / other.u)
23+
def *(other: LengthType) = LengthType(u * other.u)
24+
}
25+
26+
implicit def intToLengthType(x: Int): LengthType = LengthType(x)
27+
implicit def lengthTypeToLong(x: LengthType): Long = x.u.toLong
1728

1829
/* ------------ Base Traits -------------------------------- */
1930

0 commit comments

Comments
 (0)