RhoMicro.AlgebraicEffects 1.1.1

dotnet add package RhoMicro.AlgebraicEffects --version 1.1.1                
NuGet\Install-Package RhoMicro.AlgebraicEffects -Version 1.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RhoMicro.AlgebraicEffects" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RhoMicro.AlgebraicEffects --version 1.1.1                
#r "nuget: RhoMicro.AlgebraicEffects, 1.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RhoMicro.AlgebraicEffects as a Cake Addin
#addin nuget:?package=RhoMicro.AlgebraicEffects&version=1.1.1

// Install RhoMicro.AlgebraicEffects as a Cake Tool
#tool nuget:?package=RhoMicro.AlgebraicEffects&version=1.1.1                

RhoMicro.AlgebraicEffects

Provides an implementation of algebraic effects for C#.

If you are new to algebraic effects, here is a great explanation: https://overreacted.io/algebraic-effects-for-the-rest-of-us/

How to Use

Effects can be handles using the Effect<> type:

Effect<T>.Handle(EffectHandler<T> handler)

Effect<T>.HandleAsync(AsyncEffectHandler<T> handler)

Handle and HandleAsync both return an instance of IDisposable that manages the lifetime of the handler registration:

EffectHandler<T> myHandler = static () => EffectHandlerResult<T>.CreateFromResult("Some Result");
using(var lt = Effect<T>.Handle(myHandler)){
    //methods called here may receive the handler
}
//the handler is unregistered, methods called here may not receive it

Effects may be handled and performed synchronously or asynchronously:

EffectHandler<T> syncHandler = static () => EffectHandlerResult<T>.CreateFromResult("Some Result");
using var _ = Effect<T>.Handle(syncHandler);

EffectHandler<T> asyncHandler = static () => Task.FromResult(EffectHandlerResult<T>.CreateFromResult("Some Result"));
using var _ = Effect<T>.HandleAsync(asyncHandler);
var missingData = Effect<T>.Perform();

var moreMissingData = await Effect<T>.PerformAsync();

Effect handlers may elect not to produce a value by returning EffectHandlerResult<T>.Unit:

EffectHandler<T> myHandler = static () => EffectHandlerResult<T>.Unit;

Handlers returning EffectHandlerResult<T>.Unit will be ignored. If, upon performing an effect, there are no handlers returning a result available, an instance of UnhandledEffectException<T> will be thrown.

try{
    var missingData = Effect<T>.Perform();
}catch(UnhandledEffectException<T> specificEx){
    //handle our effect being unhandled
}catch(UnhandledEffectException generalizedEx){
    //handle any effect being unhandled
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 251 12/9/2023
1.1.0 129 12/9/2023
1.0.1 141 12/9/2023
1.0.0 130 12/9/2023