示例#1
0
        /// <summary>
        /// Repeats a list of values a specified number of times.
        /// </summary>
        /// <typeparam name="T">The type of object contained in the list.</typeparam>
        /// <param name="list">The list of values to repeat.</param>
        /// <param name="count">The number of times to repeat all elements in the source list. If <paramref name="count"/> is less than or equal to 0, an empty list is returned.</param>
        /// <returns>A list containing the source list repeated the specified number of times.</returns>
        public static IList <T> Repeat <T>(this IList <T> list, int count)
        {
            if (count <= 0)
            {
                return(ListSource.Empty <T>());
            }

            return(new Implementation.AnonymousReadOnlyList <T>(i => list[i % list.Count], () => list.Count * count));
        }
示例#2
0
        /// <summary>
        /// Returns a read-only list that generates its elements when they are read, passing the element's index to the generator delegate.
        /// </summary>
        /// <typeparam name="T">The type of elements in the list.</typeparam>
        /// <param name="generator">The delegate that is used to generate the elements. This may be <c>null</c> if <paramref name="count"/> is less than or equal to 0.</param>
        /// <param name="count">The number of elements in the list. If <paramref name="count"/> is less than or equal to 0, an empty list is returned.</param>
        /// <returns>A read-only list that generates its elements on demand.</returns>
        public static IList <T> Generate <T>(Func <int, T> generator, int count)
        {
            if (count <= 0)
            {
                return(ListSource.Empty <T>());
            }

            return(new Implementation.AnonymousReadOnlyList <T>(generator, () => count));
        }
示例#3
0
        /// <summary>
        /// Converts a single value into a list containing that value the specified number of times.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="source">The value.</param>
        /// <param name="count">The number of times <paramref name="source"/> is repeated. If <paramref name="count"/> is less than or equal to 0, an empty list is returned.</param>
        /// <returns>A read-only list containing <paramref name="count"/> elements, all equal to <paramref name="source"/>.</returns>
        public static IList <T> Repeat <T>(T source, int count)
        {
            if (count <= 0)
            {
                return(ListSource.Empty <T>());
            }

            return(new Implementation.AnonymousReadOnlyList <T>(_ => source, () => count));
        }
示例#4
0
        /// <summary>
        /// Returns a sliced list, which acts as a window into a subset of the original list.
        /// </summary>
        /// <typeparam name="T">The type of object contained in the list.</typeparam>
        /// <param name="list">The list to slice.</param>
        /// <param name="count">The number of elements in the slice. If <paramref name="count"/> is less than or equal to zero, then an empty list is returned; if <paramref name="count"/> is greater than or equal to the count of the source list, then a list equivalent to the source list is returned.</param>
        /// <returns>A list that is a slice of the source list.</returns>
        public static IList <T> Take <T>(this IList <T> list, int count)
        {
            if (count <= 0)
            {
                return(ListSource.Empty <T>());
            }

            if (count >= list.Count)
            {
                return(list);
            }

            return(new SliceList <T>(list, 0, count));
        }
示例#5
0
        /// <summary>
        /// Returns a sliced list, which acts as a window into a subset of the original list.
        /// </summary>
        /// <typeparam name="T">The type of object contained in the list.</typeparam>
        /// <param name="list">The list to slice.</param>
        /// <param name="offset">The offset into the list at which the slice begins. If <paramref name="offset"/> is less than or equal to zero, then a list equivalent to the source list is returned; if <paramref name="offset"/> is greater than or equal to the count of the source list, then an empty list is returned.</param>
        /// <returns>A list that is a slice of the source list.</returns>
        public static IList <T> Skip <T>(this IList <T> list, int offset)
        {
            if (offset <= 0)
            {
                return(list);
            }

            if (offset >= list.Count)
            {
                return(ListSource.Empty <T>());
            }

            return(new SliceList <T>(list, offset, list.Count - offset));
        }
示例#6
0
 /// <summary>
 /// Converts a single value into a sorted list containing that value the specified number of times. The list is treated as though it were sorted by the specified comparison object.
 /// </summary>
 /// <typeparam name="T">The type of the value.</typeparam>
 /// <param name="source">The value.</param>
 /// <param name="comparer">The comparison object that defines how the list is sorted.</param>
 /// <param name="count">The number of times <paramref name="source"/> is repeated. If <paramref name="count"/> is less than or equal to 0, an empty list is returned.</param>
 /// <returns>A sorted list containing <paramref name="count"/> elements, all equal to <paramref name="source"/>.</returns>
 public static ISortedList <T> Repeat <T>(T source, IComparer <T> comparer, int count)
 {
     return(new SortedListWrapper <T>(ListSource.Repeat(source, count), comparer));
 }
示例#7
0
 /// <summary>
 /// Converts a single value into a sorted list containing a single value. The list is treated as though it were sorted by the specified comparison delegate.
 /// </summary>
 /// <typeparam name="T">The type of the value.</typeparam>
 /// <param name="source">The value.</param>
 /// <param name="comparer">The comparison delegate that defines how the list is sorted.</param>
 /// <returns>A sorted list containing a single element, <paramref name="source"/>.</returns>
 public static ISortedList <T> Return <T>(T source, Func <T, T, int> comparer)
 {
     return(new SortedListWrapper <T>(ListSource.Return(source), A.Comparer(comparer)));
 }
示例#8
0
 /// <summary>
 /// Converts a single value into a sorted list containing a single value. The list is treated as though it were sorted by the default comparison object.
 /// </summary>
 /// <typeparam name="T">The type of the value.</typeparam>
 /// <param name="source">The value.</param>
 /// <returns>A sorted list containing a single element, <paramref name="source"/>.</returns>
 public static ISortedList <T> Return <T>(T source)
 {
     return(new SortedListWrapper <T>(ListSource.Return(source), Comparer <T> .Default));
 }
示例#9
0
 /// <summary>
 /// Converts a single value into a sorted list containing a single value. The list is treated as though it were sorted by the specified comparison object.
 /// </summary>
 /// <typeparam name="T">The type of the value.</typeparam>
 /// <param name="source">The value.</param>
 /// <param name="comparer">The comparison object that defines how the list is sorted.</param>
 /// <returns>A sorted list containing a single element, <paramref name="source"/>.</returns>
 public static ISortedList <T> Return <T>(T source, IComparer <T> comparer)
 {
     return(new SortedListWrapper <T>(ListSource.Return(source), comparer));
 }
示例#10
0
 /// <summary>
 /// Creates an empty sorted list. The list is sorted by the specified comparison delegate.
 /// </summary>
 /// <typeparam name="T">The type of items in the list.</typeparam>
 /// <param name="comparer">The comparison delegate.</param>
 /// <returns>An empty sorted list.</returns>
 public static ISortedList <T> Empty <T>(Func <T, T, int> comparer)
 {
     return(new SortedListWrapper <T>(ListSource.Empty <T>(), A.Comparer(comparer)));
 }
示例#11
0
 /// <summary>
 /// Creates an empty sorted list. The list is sorted by the default comparison object.
 /// </summary>
 /// <typeparam name="T">The type of items in the list.</typeparam>
 /// <returns>An empty sorted list.</returns>
 public static ISortedList <T> Empty <T>()
 {
     return(new SortedListWrapper <T>(ListSource.Empty <T>(), Comparer <T> .Default));
 }
示例#12
0
 /// <summary>
 /// Creates an empty sorted list. The list is sorted by the specified comparison object.
 /// </summary>
 /// <typeparam name="T">The type of items in the list.</typeparam>
 /// <param name="comparer">The comparison object.</param>
 /// <returns>An empty sorted list.</returns>
 public static ISortedList <T> Empty <T>(IComparer <T> comparer)
 {
     return(new SortedListWrapper <T>(ListSource.Empty <T>(), comparer));
 }
示例#13
0
 /// <summary>
 /// Converts a single value into a sorted list containing that value the specified number of times. The list is treated as though it were sorted by the specified comparison delegate.
 /// </summary>
 /// <typeparam name="T">The type of the value.</typeparam>
 /// <param name="source">The value.</param>
 /// <param name="comparer">The comparison delegate that defines how the list is sorted.</param>
 /// <param name="count">The number of times <paramref name="source"/> is repeated. If <paramref name="count"/> is less than or equal to 0, an empty list is returned.</param>
 /// <returns>A sorted list containing <paramref name="count"/> elements, all equal to <paramref name="source"/>.</returns>
 public static ISortedList <T> Repeat <T>(T source, Func <T, T, int> comparer, int count)
 {
     return(new SortedListWrapper <T>(ListSource.Repeat(source, count), A.Comparer(comparer)));
 }
示例#14
0
 /// <summary>
 /// Converts a single value into a sorted list containing that value the specified number of times. The list is treated as though it were sorted by the default comparison object.
 /// </summary>
 /// <typeparam name="T">The type of the value.</typeparam>
 /// <param name="source">The value.</param>
 /// <param name="count">The number of times <paramref name="source"/> is repeated. If <paramref name="count"/> is less than or equal to 0, an empty list is returned.</param>
 /// <returns>A sorted list containing <paramref name="count"/> elements, all equal to <paramref name="source"/>.</returns>
 public static ISortedList <T> Repeat <T>(T source, int count)
 {
     return(new SortedListWrapper <T>(ListSource.Repeat(source, count), Comparer <T> .Default));
 }