/// <summary> /// Returns the only element of a sequence, or a default value if the /// sequence is empty; this method throws an exception if there is more /// than one element in the sequence. /// </summary> /// <typeparam name="T"> /// The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">The input sequence.</param> /// <returns> /// The single element of the input sequence, or default value of type /// <typeparamref name="T"/> if the sequence contains no elements. /// </returns> public static T SingleOrDefault <T>(this IExtremaEnumerable <T> source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Take(2).AsEnumerable().SingleOrDefault()); }
/// <summary> /// Returns the first element of a sequence. /// </summary> /// <typeparam name="T"> /// The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">The input sequence.</param> /// <exception cref="InvalidOperationException"> /// The input sequence is empty.</exception> /// <returns> /// The first element of the input sequence. /// </returns> public static T First <T>(this IExtremaEnumerable <T> source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Take(1).AsEnumerable().First()); }