On 15/04/2013 06:00, H. S. Teoh wrote:
Allowing arbitrary predicates and switch-as-expression allows you to
write code that shows intent very clearly:

        // In pseudo-D syntax
        void fill(T)(T image, int x, int y) {
                image[x,y] = switch {
                        case isFillable(image,x,y): fillColor;
                        case isBorder(image,x,y): borderColor;
                        default: defaultColor;
                };
        }

We could use a conditional operator chain:

image[x,y] = isFillable(image,x,y) ? fillColor :
             isBorder(image,x,y) ? borderColor :
             defaultColor;

Reply via email to