[Issue 9942] New: Add a functional switch function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 16 13:41:19 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9942

           Summary: Add a functional switch function
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: pull
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: GenericNPC at gmail.com


--- Comment #0 from IdanArye <GenericNPC at gmail.com> 2013-04-16 13:41:18 PDT ---
Based on `condp` from
Clojure(http://clojuredocs.org/clojure_core/1.2.0/clojure.core/condp), I've
written the function `predSwitch`. It acts as the functional(=expression)
version of the `switch` statement, and it also allows a custom predicate:

    assert(2.predSwitch!"a < b"(
        1, "less then 1",
        5, "less then 5",
        10, "less then 10",
        "greater or equal to 10") == "less then 5");

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


More information about the Digitalmars-d-bugs mailing list