-
Notifications
You must be signed in to change notification settings - Fork 72
Conversation
* @define Coll `WrappedString` | ||
* @define coll wrapped string | ||
*/ | ||
final class WrappedString(val self: String) extends AbstractSeq[Char] with IndexedSeq[Char] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it’s time to have AbstractIndexedSeq
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as in the old collections. There's collection.AbstractSeq
but no collection.AbstractIndexedSeq
or immutable.Abstract*
. I'll do some more experiments and possibly open another PR. First tests show that immutable.AbstractSeq
could be worth it, but immutable.AbstractIndexedSeq
is probably not.
val s = it.knownSize | ||
if(s >= 0) b.sizeHint(s) | ||
case _ => | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that IterableOnce
has knownSize
so you don’t have to type test for Iterable
The motivation is the same as for Arrays which were originally wrapped in ArrayView but we later changed it back to WrappedArray (and ImmutableArray): It is very convenient to have an implicit conversion of a String to a Seq[Char] but a View is no longer a Seq in the new collection library.
b871ac2
to
1694421
Compare
protected[this] def fromSpecificIterable(coll: strawman.collection.Iterable[Char]): IndexedSeq[Char] = | ||
WrappedString.fromSpecific(coll) | ||
protected[this] def newSpecificBuilder(): Builder[Char, IndexedSeq[Char]] = WrappedString.newBuilder() | ||
def iterableFactory: SeqFactory[IndexedSeq] = ImmutableArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the default IndexedSeq
implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being a fixed-size array it's the most similar to String
in spirit
The motivation is the same as for Arrays which were originally
wrapped in ArrayView but we later changed it back to WrappedArray
(and ImmutableArray): It is very convenient to have an implicit
conversion of a String to a Seq[Char] but a View is no longer a Seq
in the new collection library.