2using System.Collections.Generic;
17 public static double Min(
this IEnumerable<double> values )
19 double min =
double.PositiveInfinity;
21 foreach ( var value
in values )
23 if ( value < min ) min = value;
34 public static double Max(
this IEnumerable<double> values )
36 double max =
double.NegativeInfinity;
38 foreach ( var value
in values )
40 if ( value > max ) max = value;
51 public static double Average(
this IEnumerable<double> values )
56 foreach ( var value
in values )
72 public static Vector Average(
this IEnumerable<Vector> values )
74 double xsum = 0, ysum = 0;
77 foreach ( var value
in values )
84 return new Vector( xsum / count, ysum / count );
98 public delegate TOutput Converter<in TInput, out TOutput>(TInput input);
106 public static void ForEach<T>(
this IEnumerable<T> items, Action<T> action)
108 foreach (T item
in items)
116#pragma warning disable CS1591
130 List<TOutput> outList =
new List<TOutput>();
132 foreach ( TInput item
in items )
134 outList.Add( converter( item ) );
141 public static List<T>
FindAll<T>(
this IEnumerable<T> items, Predicate<T> pred )
145 List<T> outList =
new List<T>();
147 foreach ( var item
in items )
156 public static void AddItems<T>(
this List<T> list, params T[] items) =>
157 list.AddRange(items);
159 public static void RemoveAll<T>(
this List<T> items, Predicate<T> pred )
163 foreach ( var item
in items.FindAll( pred ) )
165 items.Remove( item );
169 public static T Find<T>(
this List<T> items, Predicate<T> pred )
174 return items.Find( pred );
176 foreach ( var item
in items )
191 return Array.Find( array, pred );
193 for (
int i = 0; i < array.Length; i++)
195 if ( pred( array[i] ) )
203 public static IEnumerable<K>
FindAll<K,V>(
this Dictionary<K,V>.KeyCollection keys, Predicate<K> pred )
205 for (
int i = 0; i < keys.Count; i++ )
207 K key = keys.ElementAt( i );
208 if ( pred( key ) ) yield
return key;
212 public static void ForEach<T>(
this T[] array, Action<T> action )
214 for (
int i = 0; i < array.Length; i++ )
Apufunktioita listojen ja muiden tietorakenteiden käyttöön.
static void ForEach< T >(this T[] array, Action< T > action)
static double Max(this IEnumerable< double > values)
Laskee maksimin.
static void AddItems< T >(this List< T > list, params T[] items)
static double Min(this IEnumerable< double > values)
Laskee minimin.
static List< T > FindAll< T >(this IEnumerable< T > items, Predicate< T > pred)
static T Find< T >(this List< T > items, Predicate< T > pred)
static double Average(this IEnumerable< double > values)
Laskee keskiarvon.
static IEnumerable< K > FindAll< K, V >(this Dictionary< K, V >.KeyCollection keys, Predicate< K > pred)
static void RemoveAll< T >(this List< T > items, Predicate< T > pred)
static T ArrayFind< T >(T[] array, Predicate< T > pred)
static IEnumerable< TOutput > ConvertAll< TInput, TOutput >(this IEnumerable< TInput > items, Converter< TInput, TOutput > converter)
Muuntaa kokoelman tietyn tyyppisiä olioita kokoelmaksi toisen tyyppisiä olioita.