Repository navigation
OnixLabs.Core.Some
Represents a present optional value — the case of Optional<T> that holds an underlying value.
| Namespace | OnixLabs.Core |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → Optional<T> → Some<T>
|
| Implements |
IValueEquatable<Optional<T>> (inherited from Optional<T>) |
public sealed class Some<T> : Optional<T>
where T : notnull| Parameter | Description |
|---|---|
T |
The type of the underlying optional value. Constrained to notnull. |
Some<T> is one of the two cases of Optional<T> and signifies that a value is present. Because Optional<T> is a closed class, a C# 15 switch over Some<T> and None<T> is exhaustive without a discard arm. Instances are created through:
-
Optional<T>.Some(T)— wraps any non-nullvalue, preserving value-type defaults such as0. -
Optional<T>.Of(T?)— for non-null, non-default values only. - The implicit conversion from
T— for any non-nullvalue.
The constructor is internal, so Some<T> cannot be instantiated directly. The wrapped value is exposed through the Value property.
Some<T> inherits all members of Optional<T>, including HasValue (always true for a Some<T>), the transformation methods Match, Select, SelectMany, and the value-access methods GetValueOrDefault, GetValueOrThrow.
using OnixLabs.Core;
// Create via the static factory method.
Some<int> some = Optional<int>.Some(42);
Console.WriteLine(some.Value); // 42
Console.WriteLine(some.HasValue); // True
// Value-type defaults are preserved as Some.
Optional<int> zero = Optional<int>.Some(0);
Console.WriteLine(zero.HasValue); // True
Console.WriteLine(((Some<int>)zero).Value); // 0
// Pattern match to access the value.
Optional<string> optional = "hello";
if (optional is Some<string> s)
{
Console.WriteLine(s.Value); // hello
}| Property | Type | Description |
|---|---|---|
Value |
T |
Gets the underlying optional value held by this instance. |
public T Value { get; }Gets the underlying value held by the current Some<T> instance. This value is guaranteed to be non-null.
Returns — The underlying optional value.
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