Issue 8762 in dart: Move sort to Iterable, return an iterable (instead of changing the collection in place)

17 views
Skip to first unread message

da...@googlecode.com

unread,
Feb 25, 2013, 10:22:00 AM2/25/13
to bu...@dartlang.org
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 8762 by kev...@j832.com: Move sort to Iterable, return an
iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

.toList()..sort() hurts.

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

da...@googlecode.com

unread,
Feb 25, 2013, 10:58:38 AM2/25/13
to bu...@dartlang.org
Updates:
Status: Triaged
Labels: -Type-Defect Type-Enhancement Area-Library

Comment #1 on issue 8762 by seth...@google.com: Move sort to Iterable,
return an iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

(No comment was entered for this change.)

da...@googlecode.com

unread,
Feb 25, 2013, 11:05:49 AM2/25/13
to bu...@dartlang.org

Comment #2 on issue 8762 by kev...@j832.com: Move sort to Iterable, return
an iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

Perhaps create `Arrays.sort` to sort a List in-place?

da...@googlecode.com

unread,
Feb 25, 2013, 11:26:34 AM2/25/13
to bu...@dartlang.org

Comment #3 on issue 8762 by seaneagan1: Move sort to Iterable, return an
iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

+1. Probably still need a mutative List.sort, the lazy verion could be
called "sorted", though that sounds like a getter, and "sortedBy" probably
won't fly (see "mappedBy"), maybe "order"?

da...@googlecode.com

unread,
Apr 25, 2013, 6:00:43 PM4/25/13
to bu...@dartlang.org
Updates:
Cc: floi...@google.com

Comment #5 on issue 8762 by bl...@google.com: Move sort to Iterable, return
an iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

+1 to adding 'sorted' or something similar.

Been switching back and forth between Dart and Python, compare:
for id in sorted(operations.keys()):

to:
for (var id in operations.keys.toList()..sort()) {}

The Dart version is unwieldy and semi-incomprehensible.

da...@googlecode.com

unread,
Mar 20, 2014, 10:56:18 PM3/20/14
to bu...@dartlang.org

Comment #6 on issue 8762 by seth...@gmail.com: Move sort to Iterable,
return an iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

See also
http://stackoverflow.com/questions/20450874/how-do-i-cleanly-map-sort-fold-sort-expand-using-only-cascades-or-chaine

da...@googlecode.com

unread,
Mar 21, 2014, 5:08:52 AM3/21/14
to bu...@dartlang.org

Comment #7 on issue 8762 by l...@google.com: Move sort to Iterable, return
an iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

It seems the request is really for something like (on Iterable<E>):

List<E> toSortedList([int compare(E e1, E e2)]) =>
this.toList()..sort(compare);

While it sure is doable (it's a one-liner), it's also just a shorthand for
two existing basic operations. There is no end to the number of such
combinations we can add, but I'm not sure its really worth it. Adding more
methods on Iterable will likely make it harder to figure out which one to
use, especially when some of them are redundant.

But I also don't really feel the hurt of .toList()..sort(). It's clear what
it is doing, and it doesn't hide that it has to allocate a list.

da...@googlecode.com

unread,
Mar 21, 2014, 11:51:53 AM3/21/14
to bu...@dartlang.org

Comment #8 on issue 8762 by alankni...@google.com: Move sort to Iterable,
return an iterable (instead of changing the collection in place)
http://code.google.com/p/dart/issues/detail?id=8762

One of the hurts is in the cited stack overflow question. It does not fit
well into a chain of messages or an existing cascade, you need to
parenthesize chunks of the expression. e.g.

(list
.map((x) => x * x)
.toList()..sort())
.forEach(print);
vs.
list
.map((x) => x * x)
.sorted()
.forEach(print);

da...@googlecode.com

unread,
Jan 14, 2015, 3:26:12 PM1/14/15
to bu...@dartlang.org

Comment #9 on issue 8762 by alank...@google.com: Move sort to Iterable,
return an iterable (instead of changing the collection in place)
https://code.google.com/p/dart/issues/detail?id=8762

This keeps coming up as an irritation, lately in the context of the
formatter.

It seems to me that, at least for the complaint that it is difficult to use
in expressions, it wouldn't even require a new method. If we just said that
sort returned "this" rather than "void" then that would improve things
quite a bit.

da...@googlecode.com

unread,
Mar 20, 2015, 3:29:46 PM3/20/15
to bu...@dartlang.org
Updates:
Labels: Library-Core

Comment #11 on issue 8762 by seth...@google.com: Move sort to Iterable,
return an iterable (instead of changing the collection in place)
https://code.google.com/p/dart/issues/detail?id=8762

(No comment was entered for this change.)

da...@googlecode.com

unread,
Mar 20, 2015, 3:30:46 PM3/20/15
to bu...@dartlang.org
Updates:
Cc: l...@google.com

Comment #10 on issue 8762 by seth...@google.com: Move sort to Iterable,
return an iterable (instead of changing the collection in place)
https://code.google.com/p/dart/issues/detail?id=8762

Still hurts when I have to do list.map()..sort(). Can we make this easier
in our library without too much impact on existing code?

da...@googlecode.com

unread,
Mar 25, 2015, 2:43:00 AM3/25/15
to bu...@dartlang.org
Updates:
Status: NotPlanned

Comment #12 on issue 8762 by l...@google.com: Move sort to Iterable, return
an iterable (instead of changing the collection in place)
https://code.google.com/p/dart/issues/detail?id=8762

Adding members to iterable can generally not be done without impacting
existing code
We are not planning on adding anything more to Iterable at this point.
(At least, it has to be incredibly awesome.)
Reply all
Reply to author
Forward
0 new messages