Class Hand<T>
Similar to Pile<T> but specialized and optimized for representing a hand of items.
Namespace: Discord.Addons.MpGame.Collections
Assembly: Discord.Addons.MpGame.dll
Syntax
public sealed class Hand<T>
where T : class
Type Parameters
Name | Description |
---|---|
T | The item type. |
Constructors
| Improve this Doc View SourceHand()
Initializes a new Hand<T> to an empty state.
Declaration
public Hand()
Hand(IEnumerable<T>)
Initializes a new Hand<T> with the specified items.
Declaration
public Hand(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items | The items to put in the hand. |
Remarks
note
This constructor will filter out any items in items
that are null or are pointing to the same object instance.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Properties
| Improve this Doc View SourceCount
The amount of items currently in the hand.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceAdd(T)
Adds an item to the hand.
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to add. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AddRange(IEnumerable<T>)
Adds multiple items to the hand.
Declaration
public void AddRange(IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | items | The items to add. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AsIndexed()
Creates a snapshot if the items inside this hand with its respective 0-based index.
Declaration
public ImmutableArray<(int, T)> AsIndexed()
Returns
Type | Description |
---|---|
ImmutableArray<(T1, T2)<Int32, T>> |
Browse()
The items inside this hand.
Declaration
public ImmutableArray<T> Browse()
Returns
Type | Description |
---|---|
ImmutableArray<T> |
Clear()
Clears the entire hand and returns the items that were in it.
Declaration
public ImmutableArray<T> Clear()
Returns
Type | Description |
---|---|
ImmutableArray<T> | The collection as it was before it is cleared. |
Order(Func<ImmutableArray<T>, IEnumerable<T>>)
Orders the items using the specified function.
Declaration
public void Order(Func<ImmutableArray<T>, IEnumerable<T>> orderFunc)
Parameters
Type | Name | Description |
---|---|---|
Func<ImmutableArray<T>, IEnumerable<T>> | orderFunc | A function that produces an IEnumerable<T> in a new order. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidOperationException | The sequence produced from |
TakeAt(Int32)
Takes a item from the given index.
Declaration
public T TakeAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The 0-based index of the item to take. |
Returns
Type | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
TakeFirstOrDefault(Func<T, Boolean>)
Takes the first item that matches a given predicate.
Declaration
public T TakeFirstOrDefault(Func<T, bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
Func<T, Boolean> | predicate | The predicate to match. |
Returns
Type | Description |
---|---|
T | The first item to match the given predicate, or null if no match found. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|