ResultExtensionsLinq Class

Extension methods for linq methods using the result types Res and ResT.

Definition

Namespace: Orx.Fun.Result
Assembly: Orx.Fun.Result (in Orx.Fun.Result.dll) Version: 1.3.0+344c8bdd6f720ccfb2d8db7c61b76cf02be18f5f
C#
public static class ResultExtensionsLinq
Inheritance
Object    ResultExtensionsLinq

Methods

AllErr(IEnumerableRes) Returns whether all results in the collection are Err or not.
AllErrT(IEnumerableResT) Returns whether all results in the collection are Err or not.
AllOk(IEnumerableRes) Returns whether all results in the collection are Ok or not.
AllOkT(IEnumerableResT) Returns whether all results in the collection are Ok or not.
AnyErr(IEnumerableRes) Returns whether any of the results in the collection are Err or not.
AnyErrT(IEnumerableResT) Returns whether any of the results results in the collection are Err or not.
AnyOk(IEnumerableRes) Returns whether any of the results in the collection are Ok or not.
AnyOkT(IEnumerableResT) Returns whether any of the results results in the collection are Ok or not.
FilterMapUnwrapT Returns unwrapped values of the results of Ok variant in the collection.
C#
var array = new Res<int>[3] { Ok(0), Err<int>("errmsg"), Ok(2) };
List<int> unwrapped = array.FilterMapUnwrap();
Assert.Equal(new int[3] { 0, 2 }, unwrapped);
FirstErrT Returns Some of the error message of first Err result of the collection if any; None otherwise.
C#
var results = new Res<int>[3] { Ok(42), Err<int>("err"), Err<int>("second-err") };
Assert.Equal(Some("err"), results.FirstErr());

results = new Res<int>[1] { Ok(7) };
Assert.True(results.FirstErr().IsNone);
FirstOkT Returns Some of the value of first Ok result of the collection if any; None otherwise.
C#
var results = new Res<int>[3] { Err<int>("err"), Ok(42), Ok(7) };
Assert.Equal(Some(42), results.FirstOk());

results = new Res<int>[1] { Err<int>("err") };
Assert.True(results.FirstOk().IsNone);
LastErrT Returns Some of the value of last Ok result of the collection if any; None otherwise.
C#
var results = new Res<int>[3] { Ok(42), Err<int>("err"), Err<int>("second-err") };
Assert.Equal(Some("second-err"), results.LastErr());

results = new Res<int>[1] { Ok(7) };
Assert.True(results.LastErr().IsNone);
LastOkT Returns Some of the value of last Ok result of the collection if any; None otherwise.
C#
var results = new Res<int>[3] { Err<int>("err"), Ok(42), Ok(7) };
Assert.Equal(Some(7), results.LastOk());

results = new Res<int>[1] { Err<int>("err") };
Assert.True(results.LastOk().IsNone);
MapUnwrapT Unwraps all elements in the collection and returns Ok of the resulting list. If any of the elements is Err; then, the method returns the mapped error.
C#
var array = new Res<int>[3] { Ok(0), Ok(1), Ok(2) };
Res<List<int>> unwrapped = array.MapUnwrap();
Assert.True(unwrapped.IsOk);
Assert.Equal(new int[3] { 0, 1, 2 }, unwrapped.Unwrap());

var arrayWithErr = new Res<int>[3] { Ok(0), Err<int>("errmsg"), Ok(2) };
Res<List<int>> unwrappedWithErr = arrayWithErr.MapUnwrap();
Assert.True(unwrappedWithErr.IsErr);
Assert.Equal(Some("errmsg"), unwrappedWithErr.ErrorMessage());

See Also