Enhanced C#
Language of your choice: library documentation
Public fields | Public static fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Syntax.LNodeList Struct Reference

A list of non-null references to LNode. More...


Source file:
Inheritance diagram for Loyc.Syntax.LNodeList:
Loyc.Collections.IListAndListSource< LNode > Loyc.ICloneable< LNodeList >

Remarks

A list of non-null references to LNode.

Users of Loyc trees previously needed to refer directly to VList<LNode> so they were dependent on which list implementation is used, which is unfortunate. It is nice to have the freedom of a struct for the node list so that implementations like VList are possible, but to refer to VList by name prevents easily changing list representations.

In the future we'll probably move away from VList as a representation, mainly so that Loyc.Syntax.dll does not need to take a dependency on Loyc.Collections.dll. This struct will aid the transition.

For now, there are implicit conversions between VList<LNode> and LNodeList. These will be removed eventually.

A disadvantage of this approach is that C# does not support user-defined conversions to interfaces. Therefore, conversion to IReadOnlyList will box the wrapper instead of the underlying implementation. Ugh.

This change is issue #100: https://github.com/qwertie/ecsharp/issues/100

Public fields

LNode this[int index, LNode defaultValue] => _list[index
 
LNode defaultValue
 
int Count => _list.Count
 
bool IsReadOnly => false
 
bool IsEmpty => _list.IsEmpty
 
LNode Last => _list.Last
 

Public static fields

static readonly LNodeList Empty = new LNodeList()
 

Properties

LNode this[int index] [get, set]
 

Public Member Functions

 LNodeList (LNode item_0)
 
 LNodeList (LNode item_0, LNode item_1)
 
 LNodeList (params LNode[] items)
 
 LNodeList (IEnumerable< LNode > items)
 
 LNodeList (VList< LNode > list)
 
void ICollection< LNode >. Add (LNode item)
 
LNodeList Add (LNode item)
 
void Clear ()
 
bool Contains (LNode item)
 
void CopyTo (LNode[] array, int arrayIndex)
 
IEnumerator< LNodeGetEnumerator ()
 
int IndexOf (LNode item)
 
void IList< LNode >. Insert (int index, LNode item)
 
LNodeList Insert (int index, LNode item)
 
bool Remove (LNode item)
 
void IList< LNode >. RemoveAt (int index)
 
LNodeList RemoveAt (int index)
 
IRange< LNode > IListSource< LNode >. Slice (int start, int count)
 
Slice_< LNodeSlice (int start, int count=int.MaxValue)
 
LNode TryGet (int index, out bool fail)
 
IEnumerator IEnumerable. GetEnumerator ()
 
LNodeList ICloneable< LNodeList >. Clone ()
 
LNodeList First (int count)
 
LNodeList Initial (int count)
 
LNodeList Final (int count)
 
LNodeList WithoutLast (int count)
 
LNodeList SmartSelect (Func< LNode, LNode > map)
 Maps a list to another list of the same length. More...
 
LNodeList SmartSelectMany (Func< LNode, IReadOnlyList< LNode >> map)
 Maps a list to another list by concatenating the outputs of a mapping function. More...
 
LNodeList SmartWhere (Func< LNode, bool > filter)
 Filters the list, returning the same list if the filter function returns true for every item. More...
 
LNodeList WhereSelect (Func< LNode, Maybe< LNode >> filter)
 Filters and maps a list with a user-defined function. More...
 
LNodeList AddRange (VList< LNode > list)
 
LNodeList AddRange (LNodeList list)
 
LNodeList AddRange (IReadOnlyList< LNode > list)
 
LNodeList AddRange (IEnumerable< LNode > list)
 
LNodeList InsertRange (int index, IReadOnlyList< LNode > list)
 
LNodeList RemoveRange (int index, int count)
 
LNode Pop ()
 
bool Equals (LNodeList other)
 
override bool Equals (object rhs)
 
override int GetHashCode ()
 
override string ToString ()
 
- Public Member Functions inherited from Loyc.ICloneable< LNodeList >
Clone ()
 

Static Public Member Functions

static implicit operator LNodeList (VList< LNode > list)
 
static implicit operator VList< LNode > (LNodeList list)
 
static bool operator== (LNodeList lhs, LNodeList rhs)
 Returns whether the two list references are the same. Does not compare the contents of the lists. More...
 
static bool operator!= (LNodeList lhs, LNodeList rhs)
 Returns whether the two list references are different. Does not compare the contents of the lists. More...
 

Member Function Documentation

◆ operator!=()

static bool Loyc.Syntax.LNodeList.operator!= ( LNodeList  lhs,
LNodeList  rhs 
)
static

Returns whether the two list references are different. Does not compare the contents of the lists.

◆ operator==()

static bool Loyc.Syntax.LNodeList.operator== ( LNodeList  lhs,
LNodeList  rhs 
)
static

Returns whether the two list references are the same. Does not compare the contents of the lists.

◆ SmartSelect()

LNodeList Loyc.Syntax.LNodeList.SmartSelect ( Func< LNode, LNode map)

Maps a list to another list of the same length.

Parameters
mapA function that transforms each item in the list.
Returns
The list after the map function is applied to each item. The original list is not modified.

This method is called "Smart" because of what happens if the map doesn't do anything. If the map function returns the first N items unmodified, those N items are typically not copied, but shared between the existing list and the new one. This is useful for functional code that often processes a list without modifying it at all.

◆ SmartSelectMany()

LNodeList Loyc.Syntax.LNodeList.SmartSelectMany ( Func< LNode, IReadOnlyList< LNode >>  map)

Maps a list to another list by concatenating the outputs of a mapping function.

Parameters
mapA function that transforms each item in the list to a list of items.
Returns
A list that contains all the items returned from map.

This method is called "Smart" because of what happens if the map returns the same list again. If, for the first N items, the map returns a list of length 1, and that one item is the same item that was passed in, then those N items are typically not copied, but shared between the existing list and the new one. This is useful for functional code that often processes a list without modifying it at all.

◆ SmartWhere()

LNodeList Loyc.Syntax.LNodeList.SmartWhere ( Func< LNode, bool >  filter)

Filters the list, returning the same list if the filter function returns true for every item.

Referenced by Loyc.Syntax.LNodeExt.WithoutTrailingTrivia().

◆ WhereSelect()

LNodeList Loyc.Syntax.LNodeList.WhereSelect ( Func< LNode, Maybe< LNode >>  filter)

Filters and maps a list with a user-defined function.

Parameters
filterA function that chooses which items to include in a new list, and what to change them to.
Returns
The list after filtering has been applied. The original list structure is not modified.

This is a smart function. If the filter does not modify the first N items it is passed (which are the last items in a FVList), those N items are typically not copied, but shared between the existing list and the new one.

Referenced by Loyc.Syntax.CallNode.Select().