Ejemplo n.º 1
0
 /// <summary>
 /// Creates a shallow copy of a range of elements in the source ImmutableList&lt;T&gt;.
 /// </summary>
 /// <param name="index">
 /// The zero-based ImmutableList&lt;T&gt; 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&lt;T&gt;.
 /// </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)));
 }
Ejemplo n.º 2
0
            /// <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);
            }
Ejemplo n.º 3
0
 /// <summary>
 /// Converts the elements in the current ImmutableList&lt;T&gt; to
 /// another type, and returns a list containing the converted elements.
 /// </summary>
 /// <param name="converter">
 /// A System.Converter&lt;TInput,TOutput&gt; 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&lt;T&gt; of the target type containing the converted
 /// elements from the current ImmutableList&lt;T&gt;.
 /// </returns>
 public ImmutableList <TOutput> ConvertAll <TOutput>(Func <T, TOutput> converter)
 {
     Requires.NotNull(converter, nameof(converter));
     return(ImmutableList <TOutput> .WrapNode(_root.ConvertAll(converter)));
 }