1 /******************************************************************************* 2 * Modify 3 * Pure and functional library for modifying the contents of arrays. 4 */ 5 6 module cookbook.ingredients.arrays.modify; 7 import cookbook.essential.common; 8 import cookbook.ingredients.arrays.access; 9 10 pure T[] rev(T)(T[] data){ 11 if(data.length == 0) return []; 12 return append!T(rev(data[1..$]),data[0]); 13 } 14 15 T[] rm(T)(T[] data, T item){ 16 return filter!(((y) {return y != item;}),int)(data); 17 } 18 19 pure T[][] splitOn(T)(T[] data, T item){ 20 writefln("%s",data); 21 if(!elem!T(data,item)) 22 return [data]; 23 else return (before!T(data,item) ~ splitOn!T(after!T(data,item),item)); 24 } 25 26 pure T[] between(T)(T[] data, T item1, T item2){ //between "ab{cd}ef" { } 27 return after!T(before!T(data,item2),item1); 28 }