This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Seq.apply: s/List/ArrayBuffer/

3 replies
stepancheg
Joined: 2009-01-12,
User offline. Last seen 3 years 32 weeks ago.

Hi.

Seq.apply currently returns List, as written in
collection/immutable/Sequence.scala.

I think Seq.apply("a", "b", "z") should return ArrayBuffer, that I've
described in 5 min ago letter.

Because ArrayBuffer is significantly faster and consumes fewer memory then List.

I see only two cases when List is better then ArrayBuffer:

— List frees head, after you call drop, ArrayBuffer always holds
underlying Array. That is not a big problem (although it should be
mentioned in the scaladoc)
— List has fast prepend element operation. This not important, because
Seq has no prepend method.

So, Scala developers, please, change SequenceFactory.newBuilder method to:

def newBuilder[A, Builder[A, Sequence]] = VectorFactory.newBuilder

S.

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Seq.apply: s/List/ArrayBuffer/

On Wed, Sep 23, 2009 at 3:13 AM, Stepan Koltsov wrote:
> Hi.
>
> Seq.apply currently returns List, as written in
> collection/immutable/Sequence.scala.
>
> I think Seq.apply("a", "b", "z") should return ArrayBuffer, that I've
> described in 5 min ago letter.
>
> Because ArrayBuffer is significantly faster and consumes fewer memory then List.
>
> I see only two cases when List is better then ArrayBuffer:
>
> — List frees head, after you call drop, ArrayBuffer always holds
> underlying Array. That is not a big problem (although it should be
> mentioned in the scaladoc)
> — List has fast prepend element operation. This not important, because
> Seq has no prepend method.
>
> So, Scala developers, please, change SequenceFactory.newBuilder method to:
>
> def newBuilder[A, Builder[A, Sequence]] = VectorFactory.newBuilder
>
> S.
>
All collection classes in package collection have immutable default
implementations. Your proposal would break that consistency.

Cheers

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: Seq.apply: s/List/ArrayBuffer/
I have no particular opinion one way or the other, but perhaps it could return an immutable.Vector.

--j

On Wed, Sep 23, 2009 at 12:24 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
On Wed, Sep 23, 2009 at 3:13 AM, Stepan Koltsov <yozh [at] mx1 [dot] ru> wrote:
> Hi.
>
> Seq.apply currently returns List, as written in
> collection/immutable/Sequence.scala.
>
> I think Seq.apply("a", "b", "z") should return ArrayBuffer, that I've
> described in 5 min ago letter.
>
> Because ArrayBuffer is significantly faster and consumes fewer memory then List.
>
> I see only two cases when List is better then ArrayBuffer:
>
> — List frees head, after you call drop, ArrayBuffer always holds
> underlying Array. That is not a big problem (although it should be
> mentioned in the scaladoc)
> — List has fast prepend element operation. This not important, because
> Seq has no prepend method.
>
> So, Scala developers, please, change SequenceFactory.newBuilder method to:
>
> def newBuilder[A, Builder[A, Sequence]] = VectorFactory.newBuilder
>
> S.
>
All collection classes in package collection have immutable default
implementations. Your proposal would break that consistency.

Cheers

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: Seq.apply: s/List/ArrayBuffer/
Oops. Missed the thread right after this that suggested just that.

Sorry :)

On Wed, Sep 23, 2009 at 12:08 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
I have no particular opinion one way or the other, but perhaps it could return an immutable.Vector.

--j

On Wed, Sep 23, 2009 at 12:24 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
On Wed, Sep 23, 2009 at 3:13 AM, Stepan Koltsov <yozh [at] mx1 [dot] ru> wrote:
> Hi.
>
> Seq.apply currently returns List, as written in
> collection/immutable/Sequence.scala.
>
> I think Seq.apply("a", "b", "z") should return ArrayBuffer, that I've
> described in 5 min ago letter.
>
> Because ArrayBuffer is significantly faster and consumes fewer memory then List.
>
> I see only two cases when List is better then ArrayBuffer:
>
> — List frees head, after you call drop, ArrayBuffer always holds
> underlying Array. That is not a big problem (although it should be
> mentioned in the scaladoc)
> — List has fast prepend element operation. This not important, because
> Seq has no prepend method.
>
> So, Scala developers, please, change SequenceFactory.newBuilder method to:
>
> def newBuilder[A, Builder[A, Sequence]] = VectorFactory.newBuilder
>
> S.
>
All collection classes in package collection have immutable default
implementations. Your proposal would break that consistency.

Cheers

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland