public void TestExampleTransforms() { // These examples are listed in the documentation of FVList.Transform(). // There are more Transform() tests in VListTests() and RWListTests(). VList <int> list = new VList <int>(new int[] { -1, 2, -2, 13, 5, 8, 9 }); VList <int> output; output = list.Transform((int i, ref int n) => { // Keep every second item return((i % 2) == 1 ? XfAction.Keep : XfAction.Drop); }); ExpectList(output, 2, 13, 8); output = list.Transform((int i, ref int n) => { // Keep odd numbers return((n % 2) != 0 ? XfAction.Keep : XfAction.Drop); }); ExpectList(output, -1, 13, 5, 9); output = list.Transform((int i, ref int n) => { // Keep and square all odd numbers if ((n % 2) != 0) { n *= n; return(XfAction.Change); } else { return(XfAction.Drop); } }); ExpectList(output, 1, 169, 25, 81); output = list.Transform((int i, ref int n) => { // Increase each item by its index n += i; return(i == 0 ? XfAction.Keep : XfAction.Change); }); ExpectList(output, -1, 3, 0, 16, 9, 13, 15); list = new VList <int>(new int[] { 1, 2, 3 }); output = list.Transform(delegate(int i, ref int n) { return(i >= 0 ? XfAction.Repeat : XfAction.Keep); }); ExpectList(output, 1, 1, 2, 2, 3, 3); output = list.Transform(delegate(int i, ref int n) { if (i >= 0) { return(XfAction.Repeat); } n *= 10; return(XfAction.Change); }); ExpectList(output, 1, 10, 2, 20, 3, 30); output = list.Transform(delegate(int i, ref int n) { if (i >= 0) { n *= 10; return(XfAction.Repeat); } return(XfAction.Keep); }); ExpectList(output, 10, 1, 20, 2, 30, 3); output = list.Transform(delegate(int i, ref int n) { n *= 10; if (n > 1000) { return(XfAction.Drop); } return(XfAction.Repeat); }); ExpectList(output, 10, 100, 1000, 20, 200, 30, 300); }