Thread overview
[Issue 11572] New: eager apply for ranges
Nov 21, 2013
Martin Nowak
Nov 21, 2013
Dmitry Olshansky
Nov 22, 2013
Martin Nowak
Mar 09, 2014
Peter Alexander
November 21, 2013
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


--- Comment #0 from Martin Nowak <code@dawg.eu> 2013-11-21 12:43:30 PST ---
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 http://dlang.org/phobos/std_array.html#.array for that).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 21, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11572


bearophile_hugs@eml.cc changed:

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


--- Comment #1 from bearophile_hugs@eml.cc 2013-11-21 13:30:11 PST ---
(In reply to comment #0)
> 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: -------
November 21, 2013
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


--- Comment #2 from Dmitry Olshansky <dmitry.olsh@gmail.com> 2013-11-21 13:37:11 PST ---
(In reply to comment #1)
> (In reply to comment #0)
> > 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: -------
November 22, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11572



--- Comment #3 from Martin Nowak <code@dawg.eu> 2013-11-21 20:36:37 PST ---
(In reply to comment #2)
> 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: -------
March 09, 2014
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: -------