예제 #1
0
 /// <summary>
 /// Type-safe version of LINQs 'Single' and 'SingleOrDefault' function that returns a Maybe
 /// instead of possibly throwing an exception or returning null
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="items">A queryable of elements that we want the only element of</param>
 /// <returns>The only value in the queryable, or nothing if no such element exists or multiple elements exist</returns>
 public static IMaybe <T> MaybeSingle <T>(this IQueryable <T> items)
 {
     return(items.MaybeSingle(BasicFunctions.Const <T, bool>(true).AsExpression()));
 }
예제 #2
0
 /// <summary>
 /// Type-safe version of LINQs 'Single' and 'SingleOrDefault' function that returns a Maybe
 /// instead of possibly throwing an exception or returning null
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="items">An enumerable of elements that we want the only element of</param>
 /// <returns>The only value in the enumerable, or nothing if no such element exists or multiple elements exist</returns>
 public static IMaybe <T> MaybeSingle <T>(this IEnumerable <T> items)
 {
     return(items.MaybeSingle(BasicFunctions.Const <T, bool>(true)));
 }