/// <typeparam name="T1"> /// The first value type. /// </typeparam> /// <typeparam name="T2"> /// The second value type. /// </typeparam> /// <param name="self"> /// A <see cref="T:Cadenza.Tuple{T1,T2}" /> to convert into an <see cref="T:System.Collections.Generic.IEnumerable{System.Object}"/>. /// </param> /// <summary> /// Converts the <see cref="T:Cadenza.Tuple{T1,T2}" /> into a <see cref="T:System.Collections.Generic.IEnumerable{System.Object}"/>. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerable{System.Object}"/>. /// </returns> /// <remarks> /// <para> /// <block subset="none" type="behaviors"> /// Passes the values <see cref="P:Cadenza.Tuple`2.Item1"/>, <see cref="P:Cadenza.Tuple`2.Item2"/> to /// <paramref name="func"/>, returning the value produced by /// <paramref name="func"/>. /// </block> /// </para> /// </remarks> /// <exception cref="T:System.ArgumentNullException"> /// if <paramref name="self"/> is <see langword="null" />. /// </exception> public static System.Collections.Generic.IEnumerable <object> ToEnumerable <T1, T2>(this Tuple <T1, T2> self) { Check.Self(self); return(TupleCoda.CreateToEnumerableIterator(self)); }
public static IEnumerable <string> MatchValues(this string self, string regex, RegexOptions options) { Check.Self(self); return(Matches(self, regex, options) .Select(m => m.Value)); }
public static IEnumerable <string> Captures(this string self, string regex, RegexOptions options) { Check.Self(self); return(Matches(self, regex, options) .SelectMany(m => m.Groups.Cast <Group> ().Skip(1)) .Select(g => g.Value)); }
/// <typeparam name="T"> /// The first value type. /// </typeparam> /// <typeparam name="TResult"> /// The return value type. /// </typeparam> /// <param name="self"> /// A <see cref="T:Cadenza.Tuple{T}" /> to aggregate the values of. /// </param> /// <param name="func"> /// A <see cref="T:System.Func{T,TResult}" /> which will be invoked, providing the values /// <see cref="P:Cadenza.Tuple`1.Item1"/> /// to <paramref name="func"/> and /// returning the value returned by <paramref name="func"/>. /// </param> /// <summary> /// Converts the <see cref="T:Cadenza.Tuple{T}" /> into a <typeparamref name="TResult"/>. /// </summary> /// <returns> /// The <typeparamref name="TResult"/> returned by <paramref name="func"/>. /// </returns> /// <remarks> /// <para> /// <block subset="none" type="behaviors"> /// Passes the values <see cref="P:Cadenza.Tuple`1.Item1"/> to /// <paramref name="func"/>, returning the value produced by /// <paramref name="func"/>. /// </block> /// </para> /// </remarks> /// <exception cref="T:System.ArgumentNullException"> /// <para> /// <paramref name="self" /> is <see langword="null" />. /// </para> /// <para>-or-</para> /// <para> /// <paramref name="func" /> is <see langword="null" />. /// </para> /// </exception> public static TResult Aggregate <T, TResult>(this Tuple <T> self, System.Func <T, TResult> func) { Check.Self(self); Check.Func(func); return(func(self.Item1)); }
/// <typeparam name="T1"> /// The first value type. /// </typeparam> /// <typeparam name="T2"> /// The second value type. /// </typeparam> /// <typeparam name="T3"> /// The third value type. /// </typeparam> /// <typeparam name="T4"> /// The fourth value type. /// </typeparam> /// <typeparam name="TResult"> /// The return value type. /// </typeparam> /// <param name="self"> /// A <see cref="T:Cadenza.Tuple{T1,T2,T3,T4}" /> to aggregate the values of. /// </param> /// <param name="func"> /// A <see cref="T:System.Func{T1,T2,T3,T4,TResult}" /> which will be invoked, providing the values /// <see cref="P:Cadenza.Tuple`4.Item1"/>, <see cref="P:Cadenza.Tuple`4.Item2"/>, <see cref="P:Cadenza.Tuple`4.Item3"/>, <see cref="P:Cadenza.Tuple`4.Item4"/> /// to <paramref name="func"/> and /// returning the value returned by <paramref name="func"/>. /// </param> /// <summary> /// Converts the <see cref="T:Cadenza.Tuple{T1,T2,T3,T4}" /> into a <typeparamref name="TResult"/>. /// </summary> /// <returns> /// The <typeparamref name="TResult"/> returned by <paramref name="func"/>. /// </returns> /// <remarks> /// <para> /// <block subset="none" type="behaviors"> /// Passes the values <see cref="P:Cadenza.Tuple`4.Item1"/>, <see cref="P:Cadenza.Tuple`4.Item2"/>, <see cref="P:Cadenza.Tuple`4.Item3"/>, <see cref="P:Cadenza.Tuple`4.Item4"/> to /// <paramref name="func"/>, returning the value produced by /// <paramref name="func"/>. /// </block> /// </para> /// </remarks> /// <exception cref="T:System.ArgumentNullException"> /// <para> /// <paramref name="self" /> is <see langword="null" />. /// </para> /// <para>-or-</para> /// <para> /// <paramref name="func" /> is <see langword="null" />. /// </para> /// </exception> public static TResult Aggregate <T1, T2, T3, T4, TResult>(this Tuple <T1, T2, T3, T4> self, System.Func <T1, T2, T3, T4, TResult> func) { Check.Self(self); Check.Func(func); return(func(self.Item1, self.Item2, self.Item3, self.Item4)); }
public static IEnumerable <IEnumerable <TSource> > Rows <TSource> (this TSource[,] self) { Check.Self(self); int rows = self.GetLength(0); int cols = self.GetLength(1); return(CreateRowsIterator(self, rows, cols)); }
public static IEnumerable <KeyValuePair <TSource, TResult> > TraverseBreadthFirstWithParent <TSource, TResult>( this TSource self, Func <TSource, TResult> valueSelector, Func <TSource, IEnumerable <TSource> > childrenSelector) { Check.Self(self); Check.ValueSelector(valueSelector); Check.ChildrenSelector(childrenSelector); return(CreateTraverseBreadthFirstWithParentIterator(self, valueSelector, childrenSelector)); }
public static bool IsNullable(this Type self) { Check.Self(self); if (!self.IsValueType || !self.IsGenericType) { return(false); } return(self.IsGenericTypeDefinition ? false : self.GetGenericTypeDefinition() == typeof(Nullable <>)); }
public static string Remove(this string self, params string[] targets) { Check.Self(self); if (targets == null) { throw new ArgumentNullException("targets"); } StringBuilder builder = new StringBuilder(self); for (int i = 0; i < targets.Length; ++i) { builder.Replace(targets[i], String.Empty); } return(builder.ToString()); }
/// <typeparam name="T"> /// The first value type. /// </typeparam> /// <typeparam name="TResult"> /// The return value type. /// </typeparam> /// <param name="self"> /// A <see cref="T:Cadenza.Tuple{T}" /> to match against. /// </param> /// <param name="matchers"> /// A <see cref="T:System.Func{T,Cadenza.Maybe{TResult}}" /> /// array containing the conversion routines to use to convert /// the current <see cref="T:Cadenza.Tuple{T}" /> instance into a /// <typeparamref name="TResult" /> value. /// </param> /// <summary> /// Converts the current <see cref="T:Cadenza.Tuple{T}" /> instance into a <typeparamref name="TResult"/>. /// </summary> /// <returns> /// The <typeparamref name="TResult"/> returned by one of the <paramref name="matchers"/>. /// </returns> /// <remarks> /// <para> /// <block subset="none" type="behaviors"> /// <para> /// The current <see cref="T:Cadenza.Tuple{T}" /> instance is converted into a /// <typeparamref name="TResult" /> instance by trying each /// <see cref="T:System.Func{T,Cadenza.Maybe{TResult}}" /> /// within <paramref name="matchers" />. /// </para> /// <para> /// This method returns /// <see cref="P:Cadenza.Maybe{TResult}.Value" /> /// for the first delegate to return a /// <see cref="T:Cadenza.Maybe{TResult}" /> instance /// where <see cref="P:Cadenza.Maybe{TResult}.HasValue" /> /// is <see langword="true" />. /// </para> /// <para> /// If no <see cref="T:System.Func{T,Cadenza.Maybe{TResult}}" /> /// returns a /// <see cref="T:Cadenza.Maybe{TResult}" /> instance /// where <see cref="P:Cadenza.Maybe{TResult}.HasValue" /> /// is <see langword="true" />, then an /// <see cref="T:System.InvalidOperationException" /> is thrown. /// </para> /// </block> /// <code lang="C#"> /// var a = Tuple.Create (1, 2); /// string b = a.Match ( /// (t, v) => Match.When ( t + v == 3, "foo!"), /// (t, v) => "*default*".Just ()); /// Console.WriteLine (b); // prints "foo!"</code> /// </para> /// </remarks> /// <exception cref="T:System.ArgumentNullException"> /// <para> /// <paramref name="self" /> is <see langword="null" />. /// </para> /// <para>-or-</para> /// <para> /// <paramref name="matchers" /> is <see langword="null" />. /// </para> /// </exception> /// <exception cref="T:System.InvalidOperationException"> /// None of the /// <see cref="T:System.Func{TSource,Cadenza.Maybe{TResult}}" /> /// delegates within <paramref name="matchers" /> returned a /// <see cref="T:Cadenza.Maybe{TResult}" /> instance where /// <see cref="P:Cadenza.Maybe{TResult}.HasValue" /> was /// <see langword="true" />. /// </exception> public static TResult Match <T, TResult>(this Tuple <T> self, params System.Func <T, Cadenza.Maybe <TResult> >[] matchers) { Check.Self(self); if ((matchers == null)) { throw new System.ArgumentNullException("matchers"); } foreach (var m in matchers) { var r = m(self.Item1); if (r.HasValue) { return(r.Value); } } throw new System.InvalidOperationException("no match"); }
public static string Slice(this string self, int start, int end) { Check.Self(self); if (start < 0 || start > self.Length) { throw new ArgumentOutOfRangeException("start"); } if (end < 0) { end += self.Length + 1; } if (end < start || end > self.Length) { throw new ArgumentOutOfRangeException("end"); } return(self.Substring(start, end - start)); }
public static IEnumerable <IEnumerable <TSource> > Rows <TSource>(this TSource[][] self) { Check.Self(self); return(self); }
public static bool IsAssignableTo(this Type self, Type type) { Check.Self(self); return(type.IsAssignableFrom(self)); }
public static IEnumerable <string> Lines(this string self) { Check.Self(self); return(new StringReader(self).Lines()); }
public static TEnum ToEnum <TEnum> (this string self) { Check.Self(self); return((TEnum)Enum.Parse(typeof(TEnum), self)); }
public static ILookup <string, string> CaptureNamedGroups(this string self, string regex) { Check.Self(self); return(CaptureNamedGroups(self, regex, RegexOptions.None)); }
public static ILookup <string, string> CaptureNamedGroups(this string self, string regex, RegexOptions options) { Check.Self(self); return(CreateCaptureNamedGroupsIterator(self, regex, options).ToLookup(s => s.Key, s => s.Value)); }
public static IEnumerable <string> Captures(this string self, string regex) { Check.Self(self); return(Captures(self, regex, RegexOptions.None)); }
public static IEnumerable <Match> Matches(this string self, string regex, RegexOptions options) { Check.Self(self); return(new Regex(regex, options).Matches(self).Cast <Match> ()); }
public static IEnumerable <string> Tokens(this string self, params Func <char?, char, bool>[] categories) { Check.Self(self); return(new StringReader(self).Tokens(categories)); }