Struct Children<T>
An enumerable type representing the children of a node of type T
.
Inherited Members
Namespace: Sawmill
Assembly: Sawmill.dll
Syntax
public struct Children<T> : IImmutableList<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of the rewritable object. |
Remarks
Why not just use IEnumerable<T>? Children<T> is a value type, whereas IEnumerable<T> is a reference type. In cases where a node has a small, fixed number of children (fewer than three), it's much more efficient to pass those children around on the stack, rather than storing an enumerable on the heap which will quickly become garbage.
Properties
| Improve this Doc View SourceCount
Gets the number of values in the Children<T>.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 | The number of values in the Children<T>. |
First
Gets the first element, if NumberOfChildren is One or Two.
Declaration
public T First { get; }
Property Value
Type | Description |
---|---|
T | The first element, if NumberOfChildren is One or Two. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when NumberOfChildren is not One or Two |
Item[Int32]
Returns the element of the Children<T> at index index
.
Declaration
public T this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Property Value
Type | Description |
---|---|
T | The element of the Children<T> at index |
Many
Gets an enumerable containing the elements, if NumberOfChildren is Many.
Declaration
public ImmutableList<T> Many { get; }
Property Value
Type | Description |
---|---|
ImmutableList<T> | An enumerable containing the elements, if if NumberOfChildren is Many. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when NumberOfChildren is not Many |
NumberOfChildren
The number of children the instance contains.
Declaration
public NumberOfChildren NumberOfChildren { get; }
Property Value
Type | Description |
---|---|
NumberOfChildren | The number of children the instance contains. |
Second
Gets the second element, if NumberOfChildren is Two.
Declaration
public T Second { get; }
Property Value
Type | Description |
---|---|
T | The second element, if NumberOfChildren is Two. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when NumberOfChildren is not Two |
Methods
| Improve this Doc View SourceAdd(T)
Adds value
to the end of this Children<T>.
Declaration
public Children<T> Add(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to add |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with |
AddRange(IEnumerable<T>)
Adds items
to the end of this Children<T>.
Declaration
public Children<T> AddRange(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items | The items to add |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with |
Clear()
Returns an empty Children<T>.
Declaration
public Children<T> Clear()
Returns
Type | Description |
---|---|
Children<T> | An empty Children<T>. |
GetEnumerator()
Returns an implementation of IEnumerator<T> which yields the elements of the current instance.
Declaration
public Children<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
Children.Enumerator<> | An implementation of IEnumerator<T> which yields the elements of the current instance. |
IndexOf(T, Int32, Int32, IEqualityComparer<T>)
Finds the first occurence of item
in the count
items starting from index
using the specified IEqualityComparer<T>.
Returns the index of the item, if found; otherwise, -1.
Declaration
public int IndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to search for |
Int32 | index | The index at which to start the search |
Int32 | count | The number of items from |
IEqualityComparer<T> | equalityComparer | The equality comparer |
Returns
Type | Description |
---|---|
Int32 | The index of the item, if found; otherwise, -1. |
Insert(Int32, T)
Inserts element
into this Children<T> at index
, moving later items rightward.
Declaration
public Children<T> Insert(int index, T element)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index at which to insert |
T | element | The element to insert |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with |
InsertRange(Int32, IEnumerable<T>)
Inserts items
into this Children<T> at index
, moving later items rightward.
Declaration
public Children<T> InsertRange(int index, IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index at which to insert |
IEnumerable<T> | items | The items to insert |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with |
LastIndexOf(T, Int32, Int32, IEqualityComparer<T>)
Finds the last occurence of item
in the count
items ending at index
using the specified IEqualityComparer<T>.
Returns the index of the item, if found; otherwise, -1.
Declaration
public int LastIndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to search for |
Int32 | index | The index at which to start the search |
Int32 | count | The number of items before |
IEqualityComparer<T> | equalityComparer | The equality comparer |
Returns
Type | Description |
---|---|
Int32 | The index of the item, if found; otherwise, -1. |
Remove(T)
Removes the first occurence of value
from this Children<T>.
Declaration
public Children<T> Remove(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to remove |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with the first occurence of |
Remove(T, IEqualityComparer<T>)
Removes the first occurence of value
from this Children<T>, using the specified IEqualityComparer<T>.
Declaration
public Children<T> Remove(T value, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to remove |
IEqualityComparer<T> | equalityComparer | The equality comparer |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with the first occurence of |
RemoveAll(Predicate<T>)
Removes all the items for which match
returns true.
Declaration
public Children<T> RemoveAll(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | A predicate to apply to each item in the Children<T> |
Returns
Type | Description |
---|---|
Children<T> | A copy of the Children<T> with all the matching items removed. |
RemoveAt(Int32)
Removes the item at index
Declaration
public Children<T> RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of the item to remove |
Returns
Type | Description |
---|---|
Children<T> | A copy of the Children<T> with the item at |
RemoveRange(IEnumerable<T>)
Remove the first occurence of each item in items
Declaration
public Children<T> RemoveRange(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items | The items to remove |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with |
RemoveRange(IEnumerable<T>, IEqualityComparer<T>)
Remove the first occurence of each item in items
, using the specified using the specified IEqualityComparer<T>.
Declaration
public Children<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items | The items to remove |
IEqualityComparer<T> | equalityComparer | The equality comparer |
Returns
Type | Description |
---|---|
Children<T> | A copy of this Children<T> with |
RemoveRange(Int32, Int32)
Removes the count
items starting at index
Declaration
public Children<T> RemoveRange(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The starting index |
Int32 | count | The number of items to remove |
Returns
Type | Description |
---|---|
Children<T> | A copy of the Children<T> with the |
Replace(T, T)
Replaced the first occurence of oldValue
with newValue
Declaration
public Children<T> Replace(T oldValue, T newValue)
Parameters
Type | Name | Description |
---|---|---|
T | oldValue | The value to search for |
T | newValue | The value with which to replace |
Returns
Type | Description |
---|---|
Children<T> | A copy of the Children<T> with the first occurence of |
Replace(T, T, IEqualityComparer<T>)
Replaced the first occurence of oldValue
with newValue
, using the specified IEqualityComparer<T>.
Declaration
public Children<T> Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
T | oldValue | The value to search for |
T | newValue | The value with which to replace |
IEqualityComparer<T> | equalityComparer | The equality comparer |
Returns
Type | Description |
---|---|
Children<T> | A copy of the Children<T> with the first occurence of |
Select<U>(Func<T, U>)
Returns a new Children<T> containing the result of applying a transformation function to the elements of the current instance.
Declaration
public Children<U> Select<U>(Func<T, U> func)
Parameters
Type | Name | Description |
---|---|---|
Func<T, U> | func | A transformation function to apply to the elements of the current instance |
Returns
Type | Description |
---|---|
Children<U> | A new Children<T> containing the result of applying a transformation function to the elements of the current instance. |
Type Parameters
Name | Description |
---|---|
U |
SetItem(Int32, T)
Replaces the item at index
Declaration
public Children<T> SetItem(int index, T value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index of the item to replace with |
T | value | The value with which to replace the item at |
Returns
Type | Description |
---|---|
Children<T> | A copy of the Children<T> with the item at |
ToImmutableList()
Returns an ImmutableList<T> containing the elements of this Children<T>.
Declaration
public ImmutableList<T> ToImmutableList()
Returns
Type | Description |
---|---|
ImmutableList<T> | An ImmutableList<T> containing the elements of this Children<T>. |
Operators
| Improve this Doc View SourceImplicit(T to Children<T>)
Equivalent to Children.One(item)
Declaration
public static implicit operator Children<T>(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The child |
Returns
Type | Description |
---|---|
Children<T> |
Implicit(ImmutableList<T> to Children<T>)
Equivalent to Children.Many(list)
.
Declaration
public static implicit operator Children<T>(ImmutableList<T> list)
Parameters
Type | Name | Description |
---|---|---|
ImmutableList<T> | list | The children |
Returns
Type | Description |
---|---|
Children<T> |
Implicit((T, T) to Children<T>)
Equivalent to Children.Two(children.Item1, children.Item2)
Declaration
public static implicit operator Children<T>((T, T)children)
Parameters
Type | Name | Description |
---|---|---|
ValueTuple<T, T> | children | The children |
Returns
Type | Description |
---|---|
Children<T> |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable<T>.GetEnumerator()
Declaration
IEnumerator<T> IEnumerable<T>.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<T> |
IReadOnlyCollection<T>.Count
Declaration
int IReadOnlyCollection<T>.Count { get; }
Returns
Type | Description |
---|---|
Int32 |
IReadOnlyList<T>.Item[Int32]
Declaration
T IReadOnlyList<T>.this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Returns
Type | Description |
---|---|
T |
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |
IImmutableList<T>.Add(T)
Declaration
IImmutableList<T> IImmutableList<T>.Add(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.AddRange(IEnumerable<T>)
Declaration
IImmutableList<T> IImmutableList<T>.AddRange(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.Clear()
Declaration
IImmutableList<T> IImmutableList<T>.Clear()
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.Insert(Int32, T)
Declaration
IImmutableList<T> IImmutableList<T>.Insert(int index, T element)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | |
T | element |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.InsertRange(Int32, IEnumerable<T>)
Declaration
IImmutableList<T> IImmutableList<T>.InsertRange(int index, IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | |
IEnumerable<T> | items |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.Remove(T, IEqualityComparer<T>)
Declaration
IImmutableList<T> IImmutableList<T>.Remove(T value, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
T | value | |
IEqualityComparer<T> | equalityComparer |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.RemoveAll(Predicate<T>)
Declaration
IImmutableList<T> IImmutableList<T>.RemoveAll(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.RemoveAt(Int32)
Declaration
IImmutableList<T> IImmutableList<T>.RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.RemoveRange(IEnumerable<T>, IEqualityComparer<T>)
Declaration
IImmutableList<T> IImmutableList<T>.RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items | |
IEqualityComparer<T> | equalityComparer |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.RemoveRange(Int32, Int32)
Declaration
IImmutableList<T> IImmutableList<T>.RemoveRange(int index, int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | |
Int32 | count |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.Replace(T, T, IEqualityComparer<T>)
Declaration
IImmutableList<T> IImmutableList<T>.Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer)
Parameters
Type | Name | Description |
---|---|---|
T | oldValue | |
T | newValue | |
IEqualityComparer<T> | equalityComparer |
Returns
Type | Description |
---|---|
IImmutableList<T> |
IImmutableList<T>.SetItem(Int32, T)
Declaration
IImmutableList<T> IImmutableList<T>.SetItem(int index, T value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | |
T | value |
Returns
Type | Description |
---|---|
IImmutableList<T> |