StoneKit.Core.Structs.Maybe 1.24.611.232750

There is a newer version of this package available.
See the version list below for details.
dotnet add package StoneKit.Core.Structs.Maybe --version 1.24.611.232750
                    
NuGet\Install-Package StoneKit.Core.Structs.Maybe -Version 1.24.611.232750
                    
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="StoneKit.Core.Structs.Maybe" Version="1.24.611.232750" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StoneKit.Core.Structs.Maybe" Version="1.24.611.232750" />
                    
Directory.Packages.props
<PackageReference Include="StoneKit.Core.Structs.Maybe" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StoneKit.Core.Structs.Maybe --version 1.24.611.232750
                    
#r "nuget: StoneKit.Core.Structs.Maybe, 1.24.611.232750"
                    
#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.
#:package StoneKit.Core.Structs.Maybe@1.24.611.232750
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StoneKit.Core.Structs.Maybe&version=1.24.611.232750
                    
Install as a Cake Addin
#tool nuget:?package=StoneKit.Core.Structs.Maybe&version=1.24.611.232750
                    
Install as a Cake Tool

Maybe Monad for C#

License

Overview

The Maybe monad is a generic struct designed to represent optional values in C# following the Option Monad design pattern. It allows you to work with values that might be absent, helping to write more expressive and concise code.

This library includes extension methods for additional operations and functionalities which makes it unique by keeping the struct size as small as possible.

It has small memory footprints and performs much faster that other available implementations.

For a comprehensive understanding of the Maybe Monad, you can refer to the Pluralsight tech blog and Wikipedia on Monad (functional programming).

Installation

You can install by using NuGet:

PM> Install-Package StoneKit.Core.Strcuts.Maybe

Usage

var maybeWithValue = new Maybe<int>(42);
var maybeEmpty = Maybe<int>.Empty;
var toMaybe = 10.ToMaybe();

var maybe = Maybe<int>.Empty
    .Or(10)
    .Where(x => x > 5)
    .Perform(x=> Console.WriteLine($"{x} is greater than 5."))
    .Match(
        value => value < 50,
        value => Console.WriteLine($"{value} is smaller than 50.")
    )
    .Where(x=> x >100)
    .PerformOnEmpty(() => Console.WriteLine("Performing action on empty Maybe"))
    .Or(100)
    .Finally(x=> Console.WriteLine("I'm done!"));

Extensions

Perform

Performs an action on the value if the Maybe monad has a value.

PerformOnEmpty

Performs an action when the Maybe monad is empty.

Finally

Performs an action on the value regardless of whether the Maybe monad has a value.

Or

Returns the original Maybe monad if it has a value; otherwise, returns a new Maybe monad with the specified default value.

Map

Maps the Maybe monad from one type to another using a provided function.

MapOnEmpty

Maps the Maybe monad to another type when it is empty, using a provided function.

SelectMany

Selects and projects the value of the Maybe monad using provided functions.

Where

Filters the Maybe monad based on a predicate.

ToMaybe

Converts an object to a Maybe monad.

ToType

Converts an object to a Maybe monad of a specific type.

Contributing

If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.

License

This Maybe Monad library is licensed under the MIT License.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 (2)

Showing the top 2 NuGet packages that depend on StoneKit.Core.Structs.Maybe:

Package Downloads
StoneKit.Core.Reflection

A reflection utility containing handy extension methods and a utility for emitting IL (Intermediate Language) code using the ILGenerator.

StoneKit.TransverseMapper

Transverse - Fastest and quickest object mapper for dotnet

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2024.1.1.391401 153 10/5/2024
2024.1.1.305385 158 8/5/2024
2024.1.1.268769 139 7/9/2024
2024.1.1.261674 137 7/4/2024
2024.1.1.261665 129 7/4/2024
2024.1.1.261630 125 7/4/2024
2024.1.1.260673 165 7/3/2024
2024.1.1.260489 149 7/3/2024
2024.1.1.260485 137 7/3/2024
1.24.703.180756 289 7/3/2024
1.24.703.164604 293 7/3/2024
1.24.703.121207 533 7/3/2024
1.24.626.192706 138 6/26/2024
1.24.612.859 133 6/11/2024
1.24.611.233127 155 6/11/2024
1.24.611.232750 137 6/11/2024
1.24.603.121931 100 6/3/2024
1.24.317.170729 154 3/17/2024
1.24.317.170542 138 3/17/2024
1.24.317.164648 151 3/17/2024
1.24.317.161355 152 3/17/2024
1.24.121.184215 145 1/21/2024
1.24.121.182728 143 1/21/2024
1.23.1205.143419 213 12/5/2023
1.23.1205.132044 169 12/5/2023
1.23.1205.121843 165 12/5/2023
1.23.1205.121044 162 12/5/2023
1.23.1204.161651 156 12/4/2023
1.23.1204.155354 175 12/4/2023
1.23.1204.145217 181 12/4/2023
1.23.1201.144010 173 12/1/2023
1.23.1201.140752 154 12/1/2023
1.23.1201.135108 139 12/1/2023
1.23.1201.134244 157 12/1/2023
1.23.1201.105427 174 12/1/2023
1.23.1201.104343 169 12/1/2023
1.0.3 169 11/30/2023
1.0.2 155 11/30/2023
1.0.1 1,881 11/30/2023