Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Bring back WrappedString #351

Merged
merged 1 commit into from
Jan 22, 2018
Merged

Bring back WrappedString #351

merged 1 commit into from
Jan 22, 2018

Conversation

szeiger
Copy link
Contributor

@szeiger szeiger commented Jan 18, 2018

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.

* @define Coll `WrappedString`
* @define coll wrapped string
*/
final class WrappedString(val self: String) extends AbstractSeq[Char] with IndexedSeq[Char] {
Copy link
Contributor

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?

Copy link
Contributor Author

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 _ =>
}
Copy link
Contributor

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.
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
Copy link
Contributor

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?

Copy link
Contributor Author

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

@szeiger szeiger merged commit 8da1170 into master Jan 22, 2018
@szeiger szeiger deleted the wip/wrappedstring branch January 22, 2018 12:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants