Functional.DotNet
9.0.0-alpha
dotnet add package Functional.DotNet --version 9.0.0-alpha
NuGet\Install-Package Functional.DotNet -Version 9.0.0-alpha
<PackageReference Include="Functional.DotNet" Version="9.0.0-alpha" />
paket add Functional.DotNet --version 9.0.0-alpha
#r "nuget: Functional.DotNet, 9.0.0-alpha"
// Install Functional.DotNet as a Cake Addin #addin nuget:?package=Functional.DotNet&version=9.0.0-alpha&prerelease // Install Functional.DotNet as a Cake Tool #tool nuget:?package=Functional.DotNet&version=9.0.0-alpha&prerelease
Functional.DotNet
Installation
To start using Functional.DotNet in your C# projects, install the package from NuGet:
- Using Package Manager:
Install-Package Functional.DotNet -Version 9.0.0-alpha
- Using .NET CLI:
dotnet add package Functional.DotNet --version 9.0.0-alpha
Introduction
Welcome to Functional.DotNet, a framework designed to enhance the functional programming experience in C#. Inspired by functional programming principles, this toolset enables developers to write more efficient, readable, and maintainable C# code.
Why Choose Functional.DotNet?
- Ease of Use: Intuitive design, making functional programming in C# accessible for all levels.
- Enhanced Code Quality: Promotes writing predictable, less error-prone code.
- Seamless Integration: Integrates smoothly with existing C# projects.
Documentation
For a comprehensive guide on how to integrate and utilize Functional.DotNet in your C# projects, please refer to our official documentation.
What's New in Version 1.1.0
In version 1.1.0, we have introduced several new features to enhance your functional programming experience:
OneAmong
The OneAmong
type is a discriminated union that can hold a value of one among several possible types. It is commonly used in functional programming to represent a value that can take on different forms. Here's a sample of how to use it:
OneAmong<int, string> value = new OneAmong<int, string>(42);
value.Match(
Case<int>(x => Console.WriteLine($"It's an integer: {x}")),
Case<string>(s => Console.WriteLine($"It's a string: {s}"))
);
Agent
The Agent
type provides a simple way to manage mutable state in a functional and thread-safe manner. It encapsulates state and allows you to perform operations on it safely.
Identity
The Identity
type is a monad that wraps a value. It's a simple container for a single value and is used to bring functional programming concepts to C#.
Getting Started
Refer to our documentation for details on integrating and using this framework in your C# projects.
Learning Resources
For beginners, check out my book ["Functional C#: Embracing Functional Programming in a C# World"](https://www.amazon.de/-/en/Carlos-Bueno/dp/B0C2SW3FHL/ref=sr_1_3? crid=2LFDX227TD7NL&keywords=functional+c%23&qid=1704711844&sprefix=%2Caps%2C91&sr=8-3), a great resource for understanding C# functional programming.
“C# Functional: Monads from Zero to Hero” is an intermediate-level guide where I dive deep into the world of monads in C#. This book is designed for developers who already have a grasp of functional programming basics and want to expand their skills further. I’ll walk you through essential monad structures like Maybe<T>
, Either<L, R>
, and Task<T>
, showing how they can simplify complex logic.
Features and Code Samples
Using Try
// Example of using Try for exception-safe code
Try<Uri> CreateUri(string uri) => () => new Uri(uri);
var uriTry = CreateUri("http://github.com");
uriTry.Run().Match(
Success: uri => Assert.NotNull(uri),
Exception: ex => Fail()
);
Working with Option
// Example of using Option to handle optional values
Option<User> userOption = GetUserById(userId);
userOption.Match(
Some: user => Console.WriteLine("User found: " + user.Name),
None: () => Console.WriteLine("User not found"));
Understanding Monads
In Functional.DotNet, we delve into the concept of monads, such as Try and Option, to handle various computational contexts in a more functional way.
Contributing
Based on Enrico Buonanno's la-yumba/functional-csharp-code-2, Functional.DotNet extends these concepts to provide a comprehensive functional programming experience in C#.
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- System.Reactive (>= 6.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Functional.DotNet:
Package | Downloads |
---|---|
LDJson.Blazor
Easily generate structured data markup for Google Search using Blazor with this NuGet package. This library simplifies the creation of LD+JSON scripts, ensuring your web pages are optimized for search engine visibility and rich results. Designed for .NET 8 and C#, it integrates seamlessly into your Blazor projects, providing an efficient way to enhance your SEO strategy with minimal effort. |
|
Sitemapfy.Net
Sitemapfy.Net is a powerful .NET 8 library that facilitates the creation, serialization, and serving of XML sitemaps in ASP.NET Core applications. This package leverages the capabilities of Functional.DotNet to provide a functional programming approach for handling sitemap generation and serialization. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.0.0-alpha | 109 | 9/16/2024 |
8.1.8 | 141 | 9/26/2024 |
8.1.7 | 91 | 9/26/2024 |
8.1.6 | 85 | 9/24/2024 |
8.1.5 | 99 | 9/19/2024 |
8.1.4 | 82 | 9/19/2024 |
8.1.3 | 119 | 9/17/2024 |
8.1.2 | 101 | 9/17/2024 |
8.1.1 | 106 | 9/16/2024 |
8.1.0 | 100 | 9/16/2024 |
8.0.1 | 106 | 9/16/2024 |
8.0.0 | 119 | 9/16/2024 |
1.2.1 | 123 | 9/10/2024 |
1.2.0 | 260 | 1/26/2024 |
1.1.0 | 138 | 1/12/2024 |
1.0.4 | 111 | 1/10/2024 |
1.0.3 | 142 | 1/8/2024 |
1.0.2 | 122 | 1/7/2024 |
1.0.1 | 112 | 1/7/2024 |
1.0.0 | 110 | 1/7/2024 |