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

Deprecations in Iterable

2 replies
Florian Hars
Joined: 2008-12-18,
User offline. Last seen 42 years 45 weeks ago.

scala.Iterable deprecates take with the reason that it does not make
sense for an unordered collection, but does not deprecate takeWhile.
I think this is exactly backwards: take is perfectly useful ("just give
me n arbitrary elements from the collection, I don't care which"), while
takeWhile is useless ("give me an arbitrary number of elements
satisfying the predicate, maybe all, maybe none, I don't care").

And what is the non-deprecated way of getting the first n elements of a
SortedMap? Is it even guaranteed that the methods SortedMap inherits
from Iterable process elements in order of the keys?

- Florian.

Sean McDirmid
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Deprecations in Iterable
Use the JCL/Sorted trait. The API for grabbing keys up until Key K is "to" (weird, "from" seems to be missing, did someone delete it?). Iteration order for sorted collections is guaranteed, so the take/drop methods should be undeprecated here as they are for list. I just don't think anyone bothered to put in a "SortedIterable" or "Sorted" trait outside of the JCL, but maybe this is in Martin's redesign. 

On Sat, Jan 17, 2009 at 9:52 PM, Florian Hars <hars@bik-gmbh.de> wrote:
scala.Iterable deprecates take with the reason that it does not make sense for an unordered collection, but does not deprecate takeWhile.
I think this is exactly backwards: take is perfectly useful ("just give me n arbitrary elements from the collection, I don't care which"), while takeWhile is useless ("give me an arbitrary number of elements satisfying the predicate, maybe all, maybe none, I don't care").

And what is the non-deprecated way of getting the first n elements of a SortedMap? Is it even guaranteed that the methods SortedMap inherits from Iterable process elements in order of the keys?

- Florian.

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Deprecations in Iterable

On Sat, Jan 17, 2009 at 2:52 PM, Florian Hars wrote:
> scala.Iterable deprecates take with the reason that it does not make sense
> for an unordered collection, but does not deprecate takeWhile.
> I think this is exactly backwards: take is perfectly useful ("just give me n
> arbitrary elements from the collection, I don't care which"), while
> takeWhile is useless ("give me an arbitrary number of elements satisfying
> the predicate, maybe all, maybe none, I don't care").
>
I totally agree. Take will be undeprecated in 2.8 and takeWhile will
move to OrderedIterable.

Cheers

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