Bug 9942 – Add a functional switch function

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-16T13:41:00Z
Last change time
2014-08-10T03:17:17Z
Keywords
pull
Assigned to
nobody
Creator
GenericNPC

Comments

Comment #0 by GenericNPC — 2013-04-16T13:41:18Z
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");
Comment #1 by GenericNPC — 2013-04-16T13:51:06Z
Comment #2 by github-bugzilla — 2014-08-10T03:17:16Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/0318f0ffba8b57fe5f0edba14b41753b3f13a747 fix issue 9942 - Add a functional switch function std.algorithm.predSwitch is the functional version of the `switch` statement(without a lookup table). https://github.com/D-Programming-Language/phobos/commit/9fdee20ef3fc745d9819382184bfbfd41b6d3478 Merge pull request #1259 from idanarye/add-a-functional-switch-function fix issue 9942 - Add a functional switch function