/// <summary> /// Creates a shallow copy of a range of elements in the source ImmutableList<T>. /// </summary> /// <param name="index"> /// The zero-based ImmutableList<T> index at which the range /// starts. /// </param> /// <param name="count"> /// The number of elements in the range. /// </param> /// <returns> /// A shallow copy of a range of elements in the source ImmutableList<T>. /// </returns> public ImmutableList <T> GetRange(int index, int count) { Requires.Range(index >= 0, nameof(index)); Requires.Range(count >= 0, nameof(count)); Requires.Range(index + count <= this.Count, nameof(count)); return(ImmutableList <T> .WrapNode(Node.NodeTreeFromList(this, index, count))); }
/// <summary> /// Creates an immutable list based on the contents of this instance. /// </summary> /// <returns>An immutable list.</returns> /// <remarks> /// This method is an O(n) operation, and approaches O(1) time as the number of /// actual mutations to the set since the last call to this method approaches 0. /// </remarks> public ImmutableList <T> ToImmutable() { // Creating an instance of ImmutableList<T> with our root node automatically freezes our tree, // ensuring that the returned instance is immutable. Any further mutations made to this builder // will clone (and unfreeze) the spine of modified nodes until the next time this method is invoked. if (_immutable == null) { _immutable = ImmutableList <T> .WrapNode(this.Root); } return(_immutable); }
/// <summary> /// Converts the elements in the current ImmutableList<T> to /// another type, and returns a list containing the converted elements. /// </summary> /// <param name="converter"> /// A System.Converter<TInput,TOutput> delegate that converts each element from /// one type to another type. /// </param> /// <typeparam name="TOutput"> /// The type of the elements of the target array. /// </typeparam> /// <returns> /// A ImmutableList<T> of the target type containing the converted /// elements from the current ImmutableList<T>. /// </returns> public ImmutableList <TOutput> ConvertAll <TOutput>(Func <T, TOutput> converter) { Requires.NotNull(converter, nameof(converter)); return(ImmutableList <TOutput> .WrapNode(_root.ConvertAll(converter))); }