159 lines
3.9 KiB
C#
159 lines
3.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
|
|
namespace imm;
|
|
|
|
public record class List<T> : Timed<List<T>>, IImmutableList<T>
|
|
{
|
|
|
|
ImmutableList<T> Values = ImmutableList<T>.Empty;
|
|
|
|
|
|
|
|
public T this[int index] => (( IReadOnlyList<T> )Values)[index];
|
|
|
|
public int Count => Values.Count;
|
|
|
|
public List<T> Add( T value )
|
|
{
|
|
return this with { Values = Values.Add( value ) };
|
|
}
|
|
|
|
public List<T> AddRange( IEnumerable<T> items )
|
|
{
|
|
return this with { Values = Values.AddRange( items ) };
|
|
}
|
|
|
|
public List<T> Clear()
|
|
{
|
|
return this with { Values = Values.Clear() };
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return Values.GetEnumerator();
|
|
}
|
|
|
|
public int IndexOf( T item, int index, int count, IEqualityComparer<T> equalityComparer )
|
|
{
|
|
return Values.IndexOf( item, index, count, equalityComparer );
|
|
}
|
|
|
|
public int IndexOf( T item )
|
|
{
|
|
return Values.IndexOf( item, 0, Count, EqualityComparer<T>.Default );
|
|
}
|
|
|
|
public List<T> Insert( int index, T element )
|
|
{
|
|
return this with { Values = Values.Insert( index, element ) };
|
|
}
|
|
|
|
public List<T> InsertRange( int index, IEnumerable<T> items )
|
|
{
|
|
return this with { Values = Values.InsertRange( index, items ) };
|
|
}
|
|
|
|
public int LastIndexOf( T item, int index, int count, IEqualityComparer<T> equalityComparer )
|
|
{
|
|
return Values.LastIndexOf( item, index, count, equalityComparer );
|
|
}
|
|
|
|
|
|
|
|
public List<T> Remove( T value )
|
|
{
|
|
return Remove( value, EqualityComparer<T>.Default );
|
|
}
|
|
|
|
public List<T> Remove( T value, IEqualityComparer<T> equalityComparer )
|
|
{
|
|
return this with { Values = Values.Remove( value, equalityComparer ) };
|
|
}
|
|
|
|
public List<T> RemoveAll( Predicate<T> match )
|
|
{
|
|
return this with { Values = Values.RemoveAll( match ) };
|
|
}
|
|
|
|
public List<T> RemoveAt( int index )
|
|
{
|
|
return this with { Values = Values.RemoveAt( index ) };
|
|
}
|
|
|
|
public List<T> RemoveRange( IEnumerable<T> items, IEqualityComparer<T> equalityComparer )
|
|
{
|
|
return this with { Values = Values.RemoveRange( items, equalityComparer ) };
|
|
}
|
|
|
|
public List<T> RemoveRange( int index, int count )
|
|
{
|
|
return this with { Values = Values.RemoveRange( index, count ) };
|
|
}
|
|
|
|
public List<T> Replace( T oldValue, T newValue, IEqualityComparer<T> equalityComparer )
|
|
{
|
|
return this with { Values = Values.Replace( oldValue, newValue, equalityComparer ) };
|
|
}
|
|
|
|
public List<T> SetItem( int index, T value )
|
|
{
|
|
return this with { Values = Values.SetItem( index, value ) };
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return (( IEnumerable )Values).GetEnumerator();
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.Clear()
|
|
{
|
|
return Clear();
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.Add( T value )
|
|
{
|
|
return Add( value );
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.AddRange( IEnumerable<T> items )
|
|
{
|
|
return AddRange( items );
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.Insert( int index, T element )
|
|
{
|
|
return Insert( index, element );
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.InsertRange( int index, IEnumerable<T> items )
|
|
{
|
|
return InsertRange( index, items );
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.Remove( T value, IEqualityComparer<T> equalityComparer )
|
|
{
|
|
return Remove( value, equalityComparer );
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.RemoveAll( Predicate<T> match )
|
|
{
|
|
return RemoveAll( match );
|
|
}
|
|
|
|
IImmutableList<T> IImmutableList<T>.RemoveAt( int index ) => RemoveAt( index );
|
|
|
|
IImmutableList<T> IImmutableList<T>.RemoveRange( IEnumerable<T> items, IEqualityComparer<T> equalityComparer )
|
|
=> RemoveRange( items, equalityComparer );
|
|
|
|
IImmutableList<T> IImmutableList<T>.RemoveRange( int index, int count ) => RemoveRange( index, count );
|
|
|
|
IImmutableList<T> IImmutableList<T>.Replace( T oldValue, T newValue, IEqualityComparer<T> equalityComparer )
|
|
=> Replace( oldValue, newValue, equalityComparer );
|
|
|
|
IImmutableList<T> IImmutableList<T>.SetItem( int index, T value ) => SetItem( index, value );
|
|
}
|
|
|