ImmList <T> InsertList(int index, ImmList <T> list) { index.CheckIsBetween("index", -Root.Measure - 1, Root.Measure); list.CheckNotNull("list"); index = index < 0 ? Root.Measure + index + 1 : index; if (index == 0) { return(list.AddLastRange(this)); } if (index == Root.Measure) { return(AddLastRange(list)); } var lineage = Lineage.Mutable(); FingerTree <T> .FTree <Leaf <T> > part1, part2; Root.Split(index, out part1, out part2, Lineage.Immutable); part1 = part1.AddLastList(list.Root, Lineage.Immutable); var result = part1.AddLastList(part2, Lineage.Immutable); return(result.Wrap()); }
/// <summary> /// Concatenates another list to the beginning of this one. /// </summary> /// <param name="last">The list to add to the beginning.</param> /// <returns></returns> public ImmList <T> AddFirstRange(ImmList <T> last) { last.CheckNotNull("last"); return(AddLastList(last)); }