www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5544] New: all() and any() in Phobos

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

           Summary: all() and any() in Phobos
           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



This is Python 2.6.6 code (shell):

 items = [1, 7, 22]
 all(x % 2 for x in items)
False
 items = [1, 7, 21]
 all(x % 2 for x in items)
True The functions all() and any() are very handy. With Phobos of DMD 2.051 if you want to translate that Python code to a D2 functional style you need something like: import std.algorithm; void main() { auto items = [1, 7, 22]; bool r1 = reduce!q{a && b}(true, map!q{a % 2}(items)); assert(!r1); items = [1, 7, 21]; bool r2 = reduce!q{a && b}(true, map!q{a % 2}(items)); assert(r2); } While using an all() it becomes shorter and more readable, something like (untested): import std.algorithm; void main() { auto items = [1, 7, 22]; bool r1 = all!q{a % 2}(items); assert(!r1); items = [1, 7, 21]; bool r2 = all!q{a % 2}(items); assert(r2); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 07 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5544


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PST ---


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 07 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5544


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



Thank you for letting me know.

*** This issue has been marked as a duplicate of issue 4405 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 07 2011