Crab.NET 0.0.2

dotnet add package Crab.NET --version 0.0.2                
NuGet\Install-Package Crab.NET -Version 0.0.2                
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="Crab.NET" Version="0.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Crab.NET --version 0.0.2                
#r "nuget: Crab.NET, 0.0.2"                
#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 Crab.NET as a Cake Addin
#addin nuget:?package=Crab.NET&version=0.0.2

// Install Crab.NET as a Cake Tool
#tool nuget:?package=Crab.NET&version=0.0.2                

Crab

A collection of utilities for C#.

dotnet add package Crab.NET

Features

.Then

Extends the Task class with a .Then method that allows chaining of tasks.

var result = await Task.FromResult(1)
    .Then((result) => result + 1)
    .Then((result) => result * 2);

Mutex<T>

A mutex that wraps a value and provides a lockable guard for safe access.

// Initialize the value within the mutex
var mutex = new Mutex<List<int>>([1, 2, 3]);

// Lock and use the mutex within a `using` block
using (var guard = mutex.Lock())
{
    guard.Value.Add(1234);
}

// Works within an async context
using (var guard = await mutex.LockAsync(ct))
{
    // ...
}

// Convenience methods for mapping, the callback will run while the lock is
// acquired.
var sum = mutex.MapAsync((now) => now.Sum());

// Set a new value using a function
var ordered = mutex.SetAsync((now) => now.Order().ToList());
// Or by supplying a new value directly
var emptyList = mutex.SetAsync(new List<int>());

Result<T, E>

A result type that can represent either a successful value or an error.

// Create a method that returns a Result
private IResult<string, Exception> Greet(string input)
{
    var rb = Result.Builder<string, Exception>();

    if (string.IsNullOrEmpty(input))
        return rb.Err(new ArgumentNullException(nameof(input)));

    return rb.Ok($"Hello, {input}");
}

// Use the result
var result = Greet("world");
if (result.IsOk)
{
    Console.WriteLine(result.Unwrap());
}
else
{
    Console.WriteLine(result.UnwrapErr().Message);
}

Option<T>

An option type that can represent either a value or nothing.

// Create an option
var some = Option.Some(123);
var none = Option.None<int>();

// Use the option
if (some.TryUnwrap(out var value))
{
    Console.WriteLine(value);
}

IEnumerable.MapFilter

An extension method for IEnumerable that allows mapping and filtering in a single pass.

// Map and filter in a single pass
var result = new[] { 1, 2, 3, 4, 5 }
    .MapFilter((x) =>
    {
        if (x % 2 == 0)
            return Option.Some(x * 2);
        return Option.None<int>();
    });
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.
  • net8.0

    • No dependencies.

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
0.0.2 127 10/14/2024
0.0.1 83 10/12/2024