using System; using System.Collections.Generic; namespace JM.LinqFaster { public static partial class LinqFaster { // -------------------------- ARRAYS -------------------------------------------- /// /// Projects each element of a sequence into a new form in place. /// /// A sequence of values to invoke a transform function on (map). /// A transform function to apply (map) to each element. public static void SelectInPlaceF(this T[] source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } for (int i = 0; i < source.Length; i++) { source[i] = selector(source[i]); } } /// /// Projects each element of a sequence into a new form, in place, by incorporating the element's index. /// /// A sequence of values to invoke a transform function on. /// A transform function to apply to each source element; the second parameter of the function represents the index of the source element. public static void SelectInPlaceF(this T[] source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } for (int i = 0; i < source.Length; i++) { source[i] = selector(source[i], i); } } /// /// Projects each element of a sequence into a new form. (map in every other language) /// /// A sequence of values to invoke a transform function on (map). /// A transform function to apply (map) to each element. /// A sequence whose elements are the result of invoking the transform function on each element (mapping) of source. public static TResult[] SelectF(this T[] source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } var r = new TResult[source.Length]; for (int i = 0; i < source.Length; i++) { r[i] = selector(source[i]); } return r; } /// /// Projects each element of a sequence into a new form by incorporating the element's index. /// /// A sequence of values to invoke a transform function on. /// A transform function to apply to each source element; the second parameter of the function represents the index of the source element. /// A sequence whose elements are the result of invoking the transform function on each element of source. public static TResult[] SelectF(this T[] source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } var r = new TResult[source.Length]; for (int i = 0; i < source.Length; i++) { r[i] = selector(source[i], i); } return r; } // -------------------------- LISTS -------------------------------------------- /// /// Projects each element of a sequence into a new form in place. /// /// A sequence of values to invoke a transform function on (map). /// A transform function to apply (map) to each element. public static void SelectInPlaceF(this List source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } for (int i = 0; i < source.Count; i++) { source[i] = selector(source[i]); } } /// /// Projects each element of a sequence into a new form, in place, by incorporating the element's index. /// /// A sequence of values to invoke a transform function on. /// A transform function to apply to each source element; the second parameter of the function represents the index of the source element. public static void SelectInPlaceF(this List source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } for (int i = 0; i < source.Count; i++) { source[i] = selector(source[i], i); } } /// /// Projects each element of a sequence into a new form. (map in every other language) /// /// A sequence of values to invoke a transform function on (map). /// A transform function to apply (map) to each element. /// A sequence whose elements are the result of invoking the transform function on each element (mapping) of source. public static List SelectF(this List source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } var r = new List(source.Count); for (int i = 0; i < source.Count; i++) { r.Add(selector(source[i])); } return r; } /// /// Projects each element of a sequence into a new form by incorporating the element's index. /// /// A sequence of values to invoke a transform function on. /// A transform function to apply to each source element; the second parameter of the function represents the index of the source element. /// A sequence whose elements are the result of invoking the transform function on each element of source. public static List SelectF(this List source, Func selector) { if (source == null) { throw Error.ArgumentNull("source"); } if (selector == null) { throw Error.ArgumentNull("selector"); } var r = new List(source.Count); for (int i = 0; i < source.Count; i++) { r.Add(selector(source[i],i)); } return r; } } }