www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11572] New: eager apply for ranges

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11572

           Summary: eager apply for ranges
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: code dawg.eu



The use-case

foreach (c; "foobar".retro())
    writeln(c);

"foobar".retro.apply!writeln();

This is not a functional component because it's mostly useful for void
functions with side effect. Currently one needs to mix foreach and UFCS.

Not sure about the name, maybe sink or apply.
Or we could modify std.algorithm.reduce to allow void functions.

NB: The function is not supposed to produce a result (we have


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 21 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11572


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc




 The use-case
 
 foreach (c; "foobar".retro())
     writeln(c);
 
 "foobar".retro.apply!writeln();
This is a common need, perhaps such request is already in Bugzilla.
 Not sure about the name, maybe sink or apply.
"sink" is probably better left for output ranges, etc. "apply" function usually has another meaning: http://en.wikipedia.org/wiki/Apply So I suggest names like "forEach", that underlines its imperative nature.
 Or we could modify std.algorithm.reduce to allow void functions.
Reduce has a different meaning. Here you are not "reducing".
 Currently one needs to mix foreach and UFCS.
-- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11572


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com



13:37:11 PST ---


 The use-case
 
 foreach (c; "foobar".retro())
     writeln(c);
 
 "foobar".retro.apply!writeln();
This is a common need, perhaps such request is already in Bugzilla.
 Not sure about the name, maybe sink or apply.
"sink" is probably better left for output ranges, etc. "apply" function usually has another meaning: http://en.wikipedia.org/wiki/Apply So I suggest names like "forEach", that underlines its imperative nature.
Simply each is enough and has precedents in other languages like Groovy and Ruby. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11572





 Simply each is enough and has precedents in other languages like Groovy and
 Ruby.
Yep, 'each' is good. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 21 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11572


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au gmail.co
                   |                            |m
           Severity|normal                      |enhancement


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2014