digitalmars.D.bugs - [Issue 6035] New: std.algorithm.reversed()
- d-bugmail puremagic.com (38/43) May 18 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6035
- d-bugmail puremagic.com (6/6) May 18 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6035
- d-bugmail puremagic.com (10/10) May 18 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6035
- d-bugmail puremagic.com (12/13) May 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6035
http://d.puremagic.com/issues/show_bug.cgi?id=6035
Summary: std.algorithm.reversed()
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
std.algorithm has a reverse() function:
http://www.digitalmars.com/d/2.0/phobos/std_algorithm.html#reverse
(reverse() returns void, this is correct and right, because it works in-place.
Returning the reversed array is the wrong thing to do.)
reverse duplicates what the array reverse attribute performs:
auto a = [1, 2, 3];
a.reverse;
But in functional-style code I want to create expressions, so I can't use a
function (a procedure) that returns void:
foreach (x; reversed(foo(array1))) {...
And sometimes I don't to work-in place, I need a reversed view of something
that I don't want to modify. So I suggest to introduce a
std.algorithm.reversed() (or std.range.reversed()) function, that lazily yieds
the reversed items, as in Python:
a
['a', 'b', 'c', 'd']
a = [1, 2, 3]
reversed(a)
<listreverseiterator object at 0x01A02910>
list(reversed(a))
[3, 2, 1]
a
[1, 2, 3]
Returning a copy is also useful for immutable arrays, and generally it fits
better in functional-style programming.
See also enhancement issue 5076 that's about sorted(), another function usable
in expressions, that doesn't modify the original iterable.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6035 For an usage example see issue 6034 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 18 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6035
kennytm gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kennytm gmail.com
std.range.retro ?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6035
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
std.range.retro ?
Sorry for the noise.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19 2011









d-bugmail puremagic.com 