/// <summary> /// Sets the value of the item at the specified index. /// </summary> /// <param name="index"> The index of the item to update. </param> /// <param name="item"> The new value of the item. </param> /// <returns> </returns> /// <exception cref="ArgumentOutOfRangeException">Thrown if the index doesn't exist.</exception> public ImmList <T> Update(int index, T item) { index.CheckIsBetween("index", -Root.Measure, Root.Measure - 1); index = index < 0 ? index + Root.Measure : index; if (index == 0) { return(RemoveFirst().AddFirst(item)); } if (index == Root.Measure - 1) { return(RemoveLast().AddLast(item)); } var ret = Root.Update(index, item, Lineage.Mutable()).Wrap(); ret[index].AssertEqual(item); ret.Root.Measure.AssertEqual(Root.Measure); return(ret); }