Repository navigation
OnixLabs.Core.Collections.Collection
Provides methods to create empty or populated mutable and immutable collections, using a single, uniform naming convention across all standard collection types.
| Namespace | OnixLabs.Core.Collections |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → Collection
|
public static partial class CollectionCollection exists to make collection construction read consistently regardless of the target type. Each factory comes in two flavours:
- An
Empty…method that produces an empty collection of the named type. - An
…Ofmethod that produces a collection of the named type populated with the supplied items.
The factory methods are thin wrappers that defer to collection-expression initializers, copy constructors, or the corresponding Immutable*.CreateRange builders. Immutable empties reuse the canonical shared empty instance where one exists (for example, ImmutableDictionary<TKey, TValue>.Empty).
The Dictionary/SortedDictionary/ImmutableDictionary/ImmutableSortedDictionary factories constrain TKey with where TKey : notnull.
using OnixLabs.Core.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
List<int> emptyList = Collection.EmptyList<int>();
int[] numbers = Collection.ArrayOf(1, 2, 3);
ImmutableList<string> names = Collection.ImmutableListOf("Alice", "Bob");
HashSet<int> set = Collection.HashSetOf(1, 1, 2, 3); // { 1, 2, 3 }using OnixLabs.Core.Collections;
using System.Collections.Generic;
Dictionary<string, int> fromTuples = Collection.DictionaryOf(
("one", 1),
("two", 2));
Dictionary<string, int> fromPairs = Collection.DictionaryOf(
new KeyValuePair<string, int>("three", 3));Each method returns a new, empty instance of the named collection type.
| Method | Returns | Description |
|---|---|---|
EmptyEnumerable<T>() |
IEnumerable<T> |
Creates an empty enumerable. |
EmptyArray<T>() |
T[] |
Creates an empty array. |
EmptyImmutableArray<T>() |
ImmutableArray<T> |
Creates an empty immutable array. |
EmptyList<T>() |
List<T> |
Creates an empty list. |
EmptyImmutableList<T>() |
ImmutableList<T> |
Creates an empty immutable list. |
EmptyDictionary<TKey, TValue>() |
Dictionary<TKey, TValue> |
Creates an empty dictionary. |
EmptyImmutableDictionary<TKey, TValue>() |
ImmutableDictionary<TKey, TValue> |
Creates an empty immutable dictionary. |
EmptySortedDictionary<TKey, TValue>() |
SortedDictionary<TKey, TValue> |
Creates an empty sorted dictionary. |
EmptyImmutableSortedDictionary<TKey, TValue>() |
ImmutableSortedDictionary<TKey, TValue> |
Creates an empty immutable sorted dictionary. |
EmptyHashSet<T>() |
HashSet<T> |
Creates an empty hash set. |
EmptyImmutableHashSet<T>() |
ImmutableHashSet<T> |
Creates an empty immutable hash set. |
EmptySortedSet<T>() |
SortedSet<T> |
Creates an empty sorted set. |
EmptyImmutableSortedSet<T>() |
ImmutableSortedSet<T> |
Creates an empty immutable sorted set. |
EmptyStack<T>() |
Stack<T> |
Creates an empty stack. |
EmptyImmutableStack<T>() |
ImmutableStack<T> |
Creates an empty immutable stack. |
EmptyQueue<T>() |
Queue<T> |
Creates an empty queue. |
EmptyImmutableQueue<T>() |
ImmutableQueue<T> |
Creates an empty immutable queue. |
public static IEnumerable<T> EmptyEnumerable<T>()Creates an empty IEnumerable<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the enumerable. |
Returns — An empty enumerable.
public static T[] EmptyArray<T>()Creates an empty T array.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the array. |
Returns — An empty array.
public static ImmutableArray<T> EmptyImmutableArray<T>()Creates an empty ImmutableArray<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the immutable array. |
Returns — An empty immutable array.
public static List<T> EmptyList<T>()Creates an empty List<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the list. |
Returns — An empty list.
public static ImmutableList<T> EmptyImmutableList<T>()Creates an empty ImmutableList<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the immutable list. |
Returns — An empty immutable list.
public static Dictionary<TKey, TValue> EmptyDictionary<TKey, TValue>() where TKey : notnullCreates an empty Dictionary<TKey, TValue>.
| Type Parameter | Description |
|---|---|
TKey |
The underlying type of the dictionary key. |
TValue |
The underlying type of the dictionary value. |
Returns — An empty dictionary.
public static ImmutableDictionary<TKey, TValue> EmptyImmutableDictionary<TKey, TValue>() where TKey : notnullCreates an empty ImmutableDictionary<TKey, TValue>.
| Type Parameter | Description |
|---|---|
TKey |
The underlying type of the immutable dictionary key. |
TValue |
The underlying type of the immutable dictionary value. |
Returns — An empty immutable dictionary.
public static SortedDictionary<TKey, TValue> EmptySortedDictionary<TKey, TValue>() where TKey : notnullCreates an empty SortedDictionary<TKey, TValue>.
| Type Parameter | Description |
|---|---|
TKey |
The underlying type of the sorted dictionary key. |
TValue |
The underlying type of the sorted dictionary value. |
Returns — An empty sorted dictionary.
public static ImmutableSortedDictionary<TKey, TValue> EmptyImmutableSortedDictionary<TKey, TValue>() where TKey : notnullCreates an empty ImmutableSortedDictionary<TKey, TValue>.
| Type Parameter | Description |
|---|---|
TKey |
The underlying type of the immutable sorted dictionary key. |
TValue |
The underlying type of the immutable sorted dictionary value. |
Returns — An empty immutable sorted dictionary.
public static HashSet<T> EmptyHashSet<T>()Creates an empty HashSet<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the hash set. |
Returns — An empty hash set.
public static ImmutableHashSet<T> EmptyImmutableHashSet<T>()Creates an empty ImmutableHashSet<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the immutable hash set. |
Returns — An empty immutable hash set.
public static SortedSet<T> EmptySortedSet<T>()Creates an empty SortedSet<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the sorted set. |
Returns — An empty sorted set.
public static ImmutableSortedSet<T> EmptyImmutableSortedSet<T>()Creates an empty ImmutableSortedSet<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the immutable sorted set. |
Returns — An empty immutable sorted set.
public static Stack<T> EmptyStack<T>()Creates an empty Stack<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the stack. |
Returns — An empty stack.
public static ImmutableStack<T> EmptyImmutableStack<T>()Creates an empty ImmutableStack<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the immutable stack. |
Returns — An empty immutable stack.
public static Queue<T> EmptyQueue<T>()Creates an empty Queue<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the queue. |
Returns — An empty queue.
public static ImmutableQueue<T> EmptyImmutableQueue<T>()Creates an empty ImmutableQueue<T>.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the immutable queue. |
Returns — An empty immutable queue.
Each method returns a new instance of the named collection type populated with the supplied items.
| Method | Returns | Description |
|---|---|---|
EnumerableOf<T>(params IEnumerable<T>) |
IEnumerable<T> |
Creates an enumerable of the specified items. |
ArrayOf<T>(params T[]) |
T[] |
Creates an array of the specified items. |
ImmutableArrayOf<T>(params ImmutableArray<T>) |
ImmutableArray<T> |
Creates an immutable array of the specified items. |
ListOf<T>(params List<T>) |
List<T> |
Creates a list of the specified items. |
ImmutableListOf<T>(params ImmutableList<T>) |
ImmutableList<T> |
Creates an immutable list of the specified items. |
HashSetOf<T>(params HashSet<T>) |
HashSet<T> |
Creates a hash set of the specified items. |
ImmutableHashSetOf<T>(params ImmutableHashSet<T>) |
ImmutableHashSet<T> |
Creates an immutable hash set of the specified items. |
SortedSetOf<T>(params SortedSet<T>) |
SortedSet<T> |
Creates a sorted set of the specified items. |
ImmutableSortedSetOf<T>(params ImmutableSortedSet<T>) |
ImmutableSortedSet<T> |
Creates an immutable sorted set of the specified items. |
StackOf<T>(params IEnumerable<T>) |
Stack<T> |
Creates a stack of the specified items. |
ImmutableStackOf<T>(params ImmutableStack<T>) |
ImmutableStack<T> |
Creates an immutable stack of the specified items. |
QueueOf<T>(params IEnumerable<T>) |
Queue<T> |
Creates a queue of the specified items. |
ImmutableQueueOf<T>(params ImmutableQueue<T>) |
ImmutableQueue<T> |
Creates an immutable queue of the specified items. |
DictionaryOf<TKey, TValue>(params IEnumerable<KeyValuePair<TKey, TValue>>) |
Dictionary<TKey, TValue> |
Creates a dictionary from key/value pairs. |
DictionaryOf<TKey, TValue>(params IEnumerable<(TKey, TValue)>) |
Dictionary<TKey, TValue> |
Creates a dictionary from key/value tuples. |
ImmutableDictionaryOf<TKey, TValue>(params IEnumerable<KeyValuePair<TKey, TValue>>) |
ImmutableDictionary<TKey, TValue> |
Creates an immutable dictionary from key/value pairs. |
ImmutableDictionaryOf<TKey, TValue>(params IEnumerable<(TKey, TValue)>) |
ImmutableDictionary<TKey, TValue> |
Creates an immutable dictionary from key/value tuples. |
SortedDictionaryOf<TKey, TValue>(params IEnumerable<KeyValuePair<TKey, TValue>>) |
SortedDictionary<TKey, TValue> |
Creates a sorted dictionary from key/value pairs. |
SortedDictionaryOf<TKey, TValue>(params IEnumerable<(TKey, TValue)>) |
SortedDictionary<TKey, TValue> |
Creates a sorted dictionary from key/value tuples. |
ImmutableSortedDictionaryOf<TKey, TValue>(params IEnumerable<KeyValuePair<TKey, TValue>>) |
ImmutableSortedDictionary<TKey, TValue> |
Creates an immutable sorted dictionary from key/value pairs. |
ImmutableSortedDictionaryOf<TKey, TValue>(params IEnumerable<(TKey, TValue)>) |
ImmutableSortedDictionary<TKey, TValue> |
Creates an immutable sorted dictionary from key/value tuples. |
All dictionary factories constrain TKey with where TKey : notnull.
public static IEnumerable<T> EnumerableOf<T>(params IEnumerable<T> items)Creates an IEnumerable<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<T> |
The items which will populate the enumerable. |
Returns — An enumerable populated with the specified items.
public static T[] ArrayOf<T>(params T[] items)Creates a T array of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params T[] |
The items which will populate the array. |
Returns — An array populated with the specified items.
public static ImmutableArray<T> ImmutableArrayOf<T>(params ImmutableArray<T> items)Creates an ImmutableArray<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params ImmutableArray<T> |
The items which will populate the immutable array. |
Returns — An immutable array populated with the specified items.
public static List<T> ListOf<T>(params List<T> items)Creates a List<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params List<T> |
The items which will populate the list. |
Returns — A list populated with the specified items.
public static ImmutableList<T> ImmutableListOf<T>(params ImmutableList<T> items)Creates an ImmutableList<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params ImmutableList<T> |
The items which will populate the immutable list. |
Returns — An immutable list populated with the specified items.
public static HashSet<T> HashSetOf<T>(params HashSet<T> items)Creates a HashSet<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params HashSet<T> |
The items which will populate the hash set. |
Returns — A hash set populated with the specified items.
public static ImmutableHashSet<T> ImmutableHashSetOf<T>(params ImmutableHashSet<T> items)Creates an ImmutableHashSet<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params ImmutableHashSet<T> |
The items which will populate the immutable hash set. |
Returns — An immutable hash set populated with the specified items.
public static SortedSet<T> SortedSetOf<T>(params SortedSet<T> items)Creates a SortedSet<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params SortedSet<T> |
The items which will populate the sorted set. |
Returns — A sorted set populated with the specified items.
public static ImmutableSortedSet<T> ImmutableSortedSetOf<T>(params ImmutableSortedSet<T> items)Creates an ImmutableSortedSet<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params ImmutableSortedSet<T> |
The items which will populate the immutable sorted set. |
Returns — An immutable sorted set populated with the specified items.
public static Stack<T> StackOf<T>(params IEnumerable<T> items)Creates a Stack<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<T> |
The items which will populate the stack. |
Returns — A stack populated with the specified items.
public static ImmutableStack<T> ImmutableStackOf<T>(params ImmutableStack<T> items)Creates an ImmutableStack<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params ImmutableStack<T> |
The items which will populate the immutable stack. |
Returns — An immutable stack populated with the specified items.
public static Queue<T> QueueOf<T>(params IEnumerable<T> items)Creates a Queue<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<T> |
The items which will populate the queue. |
Returns — A queue populated with the specified items.
public static ImmutableQueue<T> ImmutableQueueOf<T>(params ImmutableQueue<T> items)Creates an ImmutableQueue<T> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params ImmutableQueue<T> |
The items which will populate the immutable queue. |
Returns — An immutable queue populated with the specified items.
public static Dictionary<TKey, TValue> DictionaryOf<TKey, TValue>(
params IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnullCreates a Dictionary<TKey, TValue> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<KeyValuePair<TKey, TValue>> |
The items which will populate the dictionary. |
Returns — A dictionary populated with the specified items.
public static Dictionary<TKey, TValue> DictionaryOf<TKey, TValue>(
params IEnumerable<(TKey key, TValue value)> items) where TKey : notnullCreates a Dictionary<TKey, TValue> of the specified key/value tuples.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<(TKey key, TValue value)> |
The items which will populate the dictionary. |
Returns — A dictionary populated with the specified items.
public static ImmutableDictionary<TKey, TValue> ImmutableDictionaryOf<TKey, TValue>(
params IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnullCreates an ImmutableDictionary<TKey, TValue> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<KeyValuePair<TKey, TValue>> |
The items which will populate the immutable dictionary. |
Returns — An immutable dictionary populated with the specified items.
public static ImmutableDictionary<TKey, TValue> ImmutableDictionaryOf<TKey, TValue>(
params IEnumerable<(TKey key, TValue value)> items) where TKey : notnullCreates an ImmutableDictionary<TKey, TValue> of the specified key/value tuples.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<(TKey key, TValue value)> |
The items which will populate the immutable dictionary. |
Returns — An immutable dictionary populated with the specified items.
public static SortedDictionary<TKey, TValue> SortedDictionaryOf<TKey, TValue>(
params IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnullCreates a SortedDictionary<TKey, TValue> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<KeyValuePair<TKey, TValue>> |
The items which will populate the sorted dictionary. |
Returns — A sorted dictionary populated with the specified items.
public static SortedDictionary<TKey, TValue> SortedDictionaryOf<TKey, TValue>(
params IEnumerable<(TKey key, TValue value)> items) where TKey : notnullCreates a SortedDictionary<TKey, TValue> of the specified key/value tuples.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<(TKey key, TValue value)> |
The items which will populate the sorted dictionary. |
Returns — A sorted dictionary populated with the specified items.
public static ImmutableSortedDictionary<TKey, TValue> ImmutableSortedDictionaryOf<TKey, TValue>(
params IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnullCreates an ImmutableSortedDictionary<TKey, TValue> of the specified items.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<KeyValuePair<TKey, TValue>> |
The items which will populate the immutable sorted dictionary. |
Returns — An immutable sorted dictionary populated with the specified items.
public static ImmutableSortedDictionary<TKey, TValue> ImmutableSortedDictionaryOf<TKey, TValue>(
params IEnumerable<(TKey key, TValue value)> items) where TKey : notnullCreates an ImmutableSortedDictionary<TKey, TValue> of the specified key/value tuples.
| Parameter | Type | Description |
|---|---|---|
items |
params IEnumerable<(TKey key, TValue value)> |
The items which will populate the immutable sorted dictionary. |
Returns — An immutable sorted dictionary populated with the specified items.
ONIXLabs .NET Library · Repository · NuGet · License (Apache-2.0)
Copyright © ONIXLabs 2020. Licensed under the Apache License, Version 2.0.
- Enumeration<T>
- Optional<T>
- OptionalEqualityComparer<T>
- OptionalExtensions
- Result
- Result<T>
- ResultEqualityComparer<T>
- ResultExtensions
- Specification<T>
- Preconditions
- IValueEquatable<T>
- IValueComparable<T>
- IBinaryConvertible
- ISpanBinaryConvertible
- IMemoryBinaryConvertible
- ArrayExtensions
- ComparableExtensions
- DateTimeExtensions
- ISpanParsableExtensions
- ObjectExtensions
- RandomExtensions
- ReadOnlySequenceExtensions
- ReadOnlySpanExtensions
- StringExtensions
- Base16
- Base32
- Base58
- Base64
- IBaseCodec
- IBaseValue
- IBaseValue<T>
- Base16Codec
- Base32Codec
- Base58Codec
- Base64Codec
- Base16FormatProvider
- Base32FormatProvider
- Base58FormatProvider
- Base64FormatProvider
- EncodingExtensions
- ReadOnlySpanExtensions
- StringBuilderExtensions
- BigDecimal
- BigDecimalEqualityComparer
- BigDecimalOrdinalityComparer
- NumberInfo
- NumberInfoEqualityComparer
- NumberInfoOrdinalityComparer
- Int256
- Int512
- UInt256
- UInt512
- Float128
- Float256
- GenericMath
- NumericsExtensions
- ConversionMode
- ScaleMode
- Hash
- NamedHash
- Sha3
- Sha3Hash224
- Sha3Hash256
- Sha3Hash384
- Sha3Hash512
- Sha3Shake128
- Sha3Shake256
- MerkleTree
- MerkleTree<T>
- PrivateKey
- PublicKey
- NamedPrivateKey
- NamedPublicKey
- EcdhPrivateKey
- EcdhPublicKey
- EcdsaPrivateKey
- EcdsaPublicKey
- EddsaPrivateKey
- EddsaPublicKey
- RsaPrivateKey
- RsaPublicKey
- DigitalSignature
- DigitalSignatureAndPublicKey
- Salt
- Secret
- ICryptoPrimitive<T>
- IHashable
- IEcdhPrivateKey
- IEcdsaPrivateKey
- IEddsaPrivateKey
- IRsaPrivateKey
- IPrivateKeyDerivable<T>
- IPrivateKeyExportable
- IPrivateKeyImportable<T>
- IPrivateKeyPemImportable<T>
- IPrivateKeyPkcs8Exportable
- IPrivateKeyPkcs8Importable<T>
- IPrivateKeyPkcs8PemExportable
- IPrivateKeyRawExportable
- IPrivateKeyRawImportable<T>
- IPrivateKeyRawPemExportable
- IEcdhPublicKey
- IEcdsaPublicKey
- IEddsaPublicKey
- IRsaPublicKey
- IPublicKeyExportable
- IPublicKeyImportable<T>
- IPublicKeyPemExportable
- IPublicKeyPemImportable<T>
- IPublicKeyRawExportable
- IPublicKeyRawImportable<T>
- HashAlgorithmExtensions
- ReadOnlySpanExtensions