udash-core icon indicating copy to clipboard operation
udash-core copied to clipboard

SeqProperty direct API should be more immutable

Open ddworak opened this issue 6 years ago • 0 comments

SeqProperties based on immutable models usually return immutable collections:

model.subProp(_.vector).get //Vector[Int]

but direct usage is not quite as good:

SeqProperty(2,1,3).get //scala.collection.Seq[Int]

The choice of base Seq type was beneficial in terms of perfomance (as we sometimes avoid copying the collection), but proves to problematic, especially in Scala 2.13, where Seq aliases immutable.Seq. This introduces compatibility issues e.g. with Scalatags, which only accept immutable collections. Therefore, after 1:1 migration of our codebase for 2.13 (https://github.com/UdashFramework/udash-core/pull/434), we had to introduce .toSeq calls in some usages:

produce(p)(s => s.toSeq.render)

This particular issue was patched by explicit copying, but it's not a comprehensive solution, as ReadableSeqProperty[A] <: ReadableProperty[scala.collection.Seq[A], which introduces base Seq type to multiple API methods.

Proposed acceptance criteria:

  • only allow immutable sequences in SeqProperties (remove io.udash.properties.PropertyCreator#materializeBSeq)
  • ensure public API of SeqProperty is ISeq-based (especially .get, .listen etc.)
  • ensure consistency with above for .subSeq, .roSubSeq
  • use a thin wrapper / copy-on-write to avoid copying in all cases. This will also benefit the performance for past cases where an immutable collection was used as a model subsequence.
  • performance should be on-par with 0.8.x

ddworak avatar Oct 30 '19 10:10 ddworak