-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Widen List
AttributeType
s to Seq
#510
Comments
But where do we build an |
The hashing function of the
class FixedSizeLongSeq(value: Long) extends Seq[Long] {
def apply(i: Int): Long = if (i == 0) value else sys.error("out of bounds")
def length: Int = 1
def iterator: Iterator[Long] = Iterator(value)
override def hashCode(): Int = value.hashCode()
} And as a result, we can break the hashing logic: val seq1: Seq[Long] = Seq(1L)
val seq2: Seq[Long] = new FixedSizeLongSeq(1L)
println(Attribute("test", seq1).hashCode() == Attribute("test", seq2).hashCode()) // false
|
you make a good point. that said, I'm not sure I agree that it needs to be sealed, but I also do see the concern. hmm. I will think on this more
nowhere, actually, and it would probably be difficult to do. good shout |
I've been thinking about this a lot, and I'm not convinced that bad |
I will try to summarize the changes. Let's say we change the type to object AttributeType {
- case object StringList extends AttributeType[List[String]]
+ case object StringSeq extends AttributeType[Seq[String]]
} Then we update the object AttributeKey {
object KeySelect {
- implicit val stringListKey: KeySelect[List[String]] =
+ implicit val stringListKey: KeySelect[Seq[String]] =
}
- def stringList(name: String): AttributeKey[List[String]] =
+ def stringSeq(name: String): AttributeKey[Seq[String]] =
} And we can test the new API: Attribute("test", List("value")) // does not compile
Attribute("test", Seq("value")) // compiles
// the following examples compile
val listAsSeq: Seq[String] = List("value")
val vectorAsSeq: Seq[String] = Vector("value")
Attribute("test", listAsSeq)
Attribute("test", vectorAsSeq)
// or even via type ascription
Attribute("test", LazyList("value1", "value2"): Seq[String])
Attribute("test", Queue("value"): Seq[String]) What do we gain from these changes? Prosa) We can build an array-like attribute from (nearly) any collection: Consa) Some implementation of the Attribute("test", LazyList.continually("123"): Seq[String]) However, we can achieve the same error in the current implementation as well: Attribute("test", LazyList.continually("123").toList) But as you mentioned, a user can always find a way to break something :) |
in terms of the compilation issue, we can probably fix it by tweaking variance. in terms of someone using an infinite edit: to put it differently, your argument doesn't seem specific to |
I think it's fine, let's keep it as is. So we can move forward with #512, right? |
yup, I'm gonna jump on fixing the merge conflicts right now |
Currently, the four array
AttributeType
s are required to beList
s; however, varargs is statically of typeSeq
and at runtime (for literals) of typei.ArraySeq
. I opine that any immutableSeq
is just as safe and well-behaved asList
, and that we shouldn't force a conversion toList
.The text was updated successfully, but these errors were encountered: