[ create a new paste ] login | about

Link: http://codepad.org/Y2Oee4Y0    [ raw code | output | fork ]

GiM - D, pasted on Apr 25:
/+ Michal 'GiM' Spadlinski +/
import tango.io.Stdout;

void blink(T, U)(T t, bool delegate(ref U) cond, void delegate(ref U) act)
{
        foreach (ref a; t)
            if (cond(a))
                act(a);
}

void main()
{
    int[] x = [1,2,3,4,5,6,7,8,9];

    blink(x, 
        (ref int b){ return b%2 == 0; },
        (ref int b){ Stdout(b).newline; b+=8; } );

    Stdout ("----------").newline;

    foreach (a; x)
        Stdout (a).newline;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
4
6
8
----------
1
10
3
12
5
14
7
16
9


Create a new paste based on this one


Comments: