Jds.LanguageExt.Extras
0.3.0
See the version list below for details.
dotnet add package Jds.LanguageExt.Extras --version 0.3.0
NuGet\Install-Package Jds.LanguageExt.Extras -Version 0.3.0
<PackageReference Include="Jds.LanguageExt.Extras" Version="0.3.0" />
paket add Jds.LanguageExt.Extras --version 0.3.0
#r "nuget: Jds.LanguageExt.Extras, 0.3.0"
// Install Jds.LanguageExt.Extras as a Cake Addin #addin nuget:?package=Jds.LanguageExt.Extras&version=0.3.0 // Install Jds.LanguageExt.Extras as a Cake Tool #tool nuget:?package=Jds.LanguageExt.Extras&version=0.3.0
LanguageExt.Extras
A collection of extension methods and helpers which extend the use of LanguageExt
.
This project is not affiliated with LanguageExt and asserts no claims upon its intellectual property.
Installation
Install LanguageExt.Extras as a NuGet package, via an IDE package manager, or using the command-line instructions at nuget.org.
Use / API
Using Statements
LanguageExt.Extras extends existing LanguageExt types. As such, you'll need both LanguageExt and LanguageExt.Extras in scope.
All API examples shown below assume the following using
statements:
using LanguageExt;
using LanguageExt.Common;
using Jds.LanguageExt.Extras;
Either<TLeft, TRight>
Extensions
Either<TLeft, TRight>.BindLeftAsync<TLeft, TRight, TLeft2>(Func<TLeft, Task<Either<TLeft2, TRight>>> func)
- Executes
func
, which returns aTask<Either<TLeft2, TRight>>
, when the either is aTLeft
.
- Executes
Either<TLeft, TRight>.Filter<TLeft, TRight>(Func<TRight, bool> filter, Func<TRight, TLeft> onFalse)
- Filters right values by executing
filter
. If it returnstrue
, the existing value is returned. If it returnsfalse
, then it executesonFalse
to create aTLeft
.
- Filters right values by executing
Either<TLeft, TRight>.FilterAsync<TLeft, TRight>(Func<TRight, Task<bool>> filter, Func<TRight, TLeft> onFalse)
- Filters right values by executing
filter
. If it returnstrue
, the existing value is returned. If it returnsfalse
, then it executesonFalse
to create aTLeft
.
- Filters right values by executing
Either<TLeft, TRight>.FilterAsync<TLeft, TRight>(Func<TRight, Task<bool>> filter, Func<TRight, Task<TLeft>> onFalse)
- Filters right values by executing
filter
. If it returnstrue
, the existing value is returned. If it returnsfalse
, then it executesonFalse
to create aTLeft
.
- Filters right values by executing
Either<TLeft, TRight>.MapLeftAsync<TLeft, TRight, TLeft2>(Func<TLeft, Task<TLeft2>> func)
- Executes
func
, which returns aTask<TLeft2>
, when the either is aTLeft
.
- Executes
Either<TLeft, TRight>.Tap<TLeft, TRight>(Action<TRight> onRight, Action<TLeft> onLeft)
- Executes a side effect, e.g., logging, based upon the state of the either. The current value is returned unchanged.
Either<TLeft, TRight>.TapAsync<TLeft, TRight>(Func<TRight, Task> onSuccess, Func<TLeft, Task> onFailure)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, based upon the state of the either. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Either<TLeft, TRight>.TapLeft<TLeft, TRight>(Action<TLeft> onFailure)
- Executes a side effect, e.g., logging, when the either is a left. The current value is returned unchanged.
Either<TLeft, TRight>.TapLeftAsync<TLeft, TRight>(Func<TLeft, Task> onFailure)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, when the either is a left. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Either<TLeft, TRight>.TapRight<TLeft, TRight>(Action<TRight> onSuccess)
- Executes a side effect, e.g., logging, when the either is a right. The current value is returned unchanged.
Either<TLeft, TRight>.TapRightAsync<TLeft, TRight>(Func<TRight, Task> onSuccess)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, when the either is a right. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Either<TLeft, TRight>.ToResult<TLeft, TRight>(Func<TLeft, Exception> ifLeft)
- Converts the
Either<TLeft, TRight>
into aResult<TRight>
.
- Converts the
Either<TLeft, TRight>.ToResult<TLeft, TRight>() where TLeft : Exception
- Converts the
Either<TLeft, TRight>
into aResult<TRight>
.
- Converts the
Option<TSome>
Extensions
Option<TSome>.Tap(Action<TSome> ifSome, Action ifNone)
- Executes a side effect, e.g., logging, based upon the state of the option. The current value is returned unchanged.
Option<TSome>.TapAsync(Func<TSome,Task> ifSome, Func<Task> ifNone)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, based upon the state of the option. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Option<TSome>.TapNone(Action ifNone)
- Executes a side effect, e.g., logging, if the option is None. The current value is returned unchanged.
Option<TSome>.TapNoneAsync(Func<Task> ifNone)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, if the option is None. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Option<TSome>.TapSome(Action<TSome> ifSome)
- Executes a side effect, e.g., logging, if the option is Some. The current value is returned unchanged.
Option<TSome>.TapSomeAsync(Func<TSome,Task> ifSome)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, if the option is Some. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Option<TSome?>
.ToNonNullable()- Converts the nullable
TSome
generic argument to a non-nullableTSome
generic argument, e.g.,Option<string?>
returnsOption<string>
. The existing value is maintained unchanged. - This method assumes execution within a
#nullable
context (i.e., in a project where nullable reference types are enabled).
- Converts the nullable
Result<TSuccess>
Extensions
Result<TSuccess>.Bind<TSuccess, TNewSuccess>(Func<TSuccess, Result<TNewSuccess>> func)
- Executes
func
, which returnsResult<TNewSuccess>
, when the result is a success.
- Executes
Result<TSuccess>.BindAsync<TSuccess, TNewSuccess>(Func<TSuccess, Task<Result<TNewSuccess>>> func)
- Executes
func
, which returnsTask<Result<TNewSuccess>>
, when the result is a success.
- Executes
Result<TSuccess>.BindFailure<TSuccess>(Func<Exception, Result<TSuccess>> func)
- Executes
func
, which returnsResult<TSuccess>
, when the result is a failure.
- Executes
Result<TSuccess>.BindFailureAsync<TSuccess>(Func<Exception, Task<Result<TSuccess>>> func)
- Executes
func
, which returnsTask<Result<TSuccess>>
, when the result is a failure.
- Executes
Result<TSuccess>.Filter<TSuccess>(Func<TSuccess, bool> filter, Func<TSuccess, Exception> onFalse)
- Filters
TSuccess
values by executingfilter
. If it returnstrue
, the existing value is returned. If it returnsfalse
, then it executesonFalse
to create anException
.
- Filters
Result<TSuccess>.FilterAsync<TSuccess>(Func<TSuccess, Task<bool>> filter, Func<TSuccess, Exception> onFalse)
- Filters
TSuccess
values by executingfilter
. If it returnstrue
, the existing value is returned. If it returnsfalse
, then it executesonFalse
to create anException
.
- Filters
Result<TSuccess>.FilterAsync<TSuccess>(Func<TSuccess, Task<bool>> filter, Func<TSuccess, Task<Exception>> onFalse)
- Filters
TSuccess
values by executingfilter
. If it returnstrue
, the existing value is returned. If it returnsfalse
, then it executesonFalse
to create anException
.
- Filters
Result<TSucess>.IfFailThrow<TSuccess>()
- Throws an
InvalidOperationException
if theResult<TSucess>
is anException
, returningTSuccess
upon success.
- Throws an
Result<TSuccess>.MapFailure<TSuccess, TFailure>(Func<Exception, TFailure> func) where TFailure : Exception
- Executes
func
, which returns anException
, when the result is a failure.
- Executes
Result<TSuccess>.MapFailureAsync<TSuccess, TFailure>(Func<Exception, Task<TFailure>> func) where TFailure : Exception
- Executes
func
, which returns aTask<Exception>
, when the result is a failure.
- Executes
Result<TSuccess>.MapSafe<TSuccess, TNewSuccess>(Func<TSuccess, TNewSuccess> func)
- Executes
func
, which returnsTNewSuccess
, when the result is a success. Exceptions are caught and returned as a failure. (I.e., this simplifiesresult.Bind(value => Prelude.Try(() => func(value)).Try())
)
- Executes
Result<TSuccess>.MapSafeAsync<TSuccess, TNewSuccess>(Func<TSuccess, Task<TNewSuccess>> func)
- Executes
func
, which returnsTask<TNewSuccess>
, when the result is a success. Exceptions are caught and returned as a failure. (I.e., this simplifiesresult.BindAsync(value => Prelude.TryAsync(() => func(value)).Try())
)
- Executes
Result<TSuccess>.Tap<TSuccess>(Action<TSuccess> onSuccess, Action<Exception> onFailure)
- Executes a side effect, e.g., logging, based upon the state of the result. The current value is returned unchanged.
Result<TSuccess>.TapAsync<TSuccess>(Func<TSuccess, Task> onSuccess, Func<Exception, Task> onFailure)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, based upon the state of the result. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Result<TSuccess>.TapFailure<TSuccess>(Action<Exception> onFailure)
- Executes a side effect, e.g., logging, when the result is a failure. The current value is returned unchanged.
Result<TSuccess>.TapFailureAsync<TSuccess>(Func<Exception, Task> onFailure)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, when the result is a failure. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Result<TSuccess>.TapSuccess<TSuccess>(Action<TSuccess> onSuccess)
- Executes a side effect, e.g., logging, when the result is a success. The current value is returned unchanged.
Result<TSuccess>.TapSuccessAsync<TSuccess>(Func<TSuccess, Task> onSuccess)
- Executes an asynchronous side effect, e.g., dispatching a status notification via
HttpClient
, when the result is a success. The current value is returned unchanged.
- Executes an asynchronous side effect, e.g., dispatching a status notification via
Result<TSuccess>.ToEither<TSuccess>()
- Converts the
Result<TSuccess>
into anEither<Exception, TSuccess>
.
- Converts the
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- LanguageExt.Core (>= 4.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.