OptionExtensionsLinq Class

Extension methods for linq methods using the option type OptT.

Definition

Namespace: Orx.Fun.Option
Assembly: Orx.Fun.Option (in Orx.Fun.Option.dll) Version: 1.2.1+ea79806fa5e0e04bfdaef2a1916930e75e2cde74
C#
public static class OptionExtensionsLinq
Inheritance
Object    OptionExtensionsLinq

Methods

FilterMapUnwrapT Returns unwrapped values of the optionals of Some variant in the collection.
C#
var array = new Opt<int>[3] { Some(0), None, Some(2) };
List<int> unwrapped = array.FilterMapUnwrap();
Assert.Equal(new int[3] { 0, 2 }, unwrapped);
FirstOrNoneT(IEnumerableT) Returns Some of the first element of the collection if it is non-empty; None otherwise.
C#
Assert.True(Array.Empty<Title>().FirstOrNone().IsNone);
Assert.True((new int[2] { 1, 2 }).FirstOrNone() == Some(1));
FirstOrNoneT(IEnumerableT, FuncT, Boolean) Returns Some of the first element of the collection satisfying the filter if any; None otherwise.
C#
Assert(Array.Empty<int>().FirstOrNone(x => x > 2).IsNone);
Assert((new int[2] { 1, 2 }).FirstOrNone(x => x > 2).IsNone);
Assert((new int[2] { 1, 2 }).FirstOrNone(x => x > 1) == Some(2));
GetT(T, Int32) Returns Some of the element at the given index of the array if it is a valid index; None otherwise.
C#
Assert(Array.Empty<Title>().Get(1).IsNone);
Assert((new int[2] { 1, 2 }).Get(2) == Some(1));
Assert((new int[2] { 1, 2 }).Get(0) == Some(1));
GetT(MemoryT, Void) 
GetT(ReadOnlyMemoryT, Void) 
GetT(ReadOnlySpanT, Void) 
GetT(SpanT, Void) 
GetK, V(DictionaryTKey, TValue, Boolean) 
GetT, L(L, Int32) Returns Some of the element at the given index of the list if it is a valid index; None otherwise.
C#
Assert(Array.Empty<Title>().Get(1).IsNone);
Assert((new List<int>() { 1, 2 }).Get(2) == Some(1));
Assert((new List<int>() { 1, 2 }).Get(0) == Some(1));
GetNonEnumeratedCountT Returns Some of the count of elements in the collection if the count is readily available without enumeration; None otherwise.
C#
var array = new int[3] { 0, 1, 2 };
Assert.Equal(Some(3), array.GetNonEnumeratedCount());

var odds = array.Where(num => num % 2 == 1);
Assert.Equal(None<int>(), odds.GetNonEnumeratedCount());
LastOrNoneT(IEnumerableT) Returns Some of the last element of the collection if it is non-empty; None otherwise.
C#
Assert(Array.Empty<Title>().FirstOrNone().IsNone);
Assert((new int[2] { 1, 2 }).LastOrNone() == Some(2));
LastOrNoneT(IEnumerableT, FuncT, Boolean) Returns Some of the last element of the collection satisfying the filter if any; None otherwise.
C#
Assert(Array.Empty<int>().LastOrNone(x => x > 2).IsNone);
Assert((new int[2] { 2, 1 }).LastOrNone(x => x > 2).IsNone);
Assert((new int[2] { 2, 1 }).LastOrNone(x => x > 1) == Some(2));
MapUnwrapT 

See Also