Created
November 2, 2012 21:04
This file contains 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
case class Foo(id: Key = genKey) | |
case class Bar(x: String, foo: Key = null, id: Key = genKey) | |
// in tests | |
Bar(testData, testFoo.id, testBarId) | |
// somewhere in logic | |
Bar(sensitiveData, foo.id) |
This file contains 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
case class Foo(id: Id[Foo] = genId) | |
case class Bar(x: String, foo: Id[Foo] = null, id: Id[Bar] = genId) | |
// in tests | |
Bar(testData, testFoo.id, testBarId) | |
// somewhere in logic | |
Bar(sensitiveData, foo.id) |
This file contains 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
scala> import shapeless.TypeOperators._ | |
import shapeless.TypeOperators._ | |
scala> type MyString = Newtype[String, Any] | |
defined type alias MyString | |
scala> val x: MyString = newtype("test") | |
x: MyString = test | |
scala> x.getClass | |
res4: java.lang.Class[_ <: AnyRef] = class java.lang.String |
This file contains 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
import shapeless._ | |
import shapeless.TypeOperators._ | |
trait Stub[T] {} | |
type Id[T] = Newtype[Key, Stub[T]] | |
def Id[T](s: Key): Id[T] = newtype(s) |
This file contains 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
case class Foo(id: Key) | |
case class Baz(id: Key) | |
case class Bar(x: String, baz: Key = null, foo: Key = null, id: Key = genKey) | |
// in tests | |
Bar(testData, testFoo.id, testBarId) // messed up! | |
// somewhere in logic | |
Bar(sensitiveData, foo.id) // messed up! |
This file contains 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
case class Foo(id: Id[Foo]) | |
case class Baz(id: Id[Baz]) | |
case class Bar(x: String, baz: Id[Baz] = null, foo: Id[Bar] = null, id: Id[Bar] = genKey) | |
// in tests | |
Bar(testData, testFoo.id, testBarId) // compile error! | |
// somewhere in logic | |
Bar(sensitiveData, foo.id) // compile error! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment