A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/la-yumba/functional-csharp-code below:

la-yumba/functional-csharp-code: Code samples for Functional Programming in C#

Functional Programming in C#

This repo contains the code samples, exercises and solutions for the book Functional Programming in C# published by Manning.

The code samples are organized in the following projects:

Note: you are welcome to reference LaYumba.Functional from your projects via NuGet, and submit PRs with improvements, but the main intent of this library is pedagogical. For a more fully-fledged functional library, consider LanguageExt

Working with the code samples

The code samples use .NET Standard 1.6 and .NET Core 2.0, and should compile and run on all major OS's via the dotnet CLI.

To check this is available, type dotnet --version at the command prompt, and you should get 2.0.3 or greater

$ git clone git@github.com:la-yumba/functional-csharp-code.git
$ cd functional-csharp-code
$ dotnet restore

Use the dotnet test command, for example:

$ cd LaYumba.Functional.Tests
$ dotnet test

tests in the Exercises and Examples projects can be run in the same way.

Many code samples in the book can be run, in case you'd like to debug or "see that it works". The pattern is:

$ cd Examples
$ dotnet run Greetings
Section Command 7.1 dotnet run Greetings

Throughout the book, I encourage readers to try things out in the REPL.

You'll often need to import LaYumba.Functional in the REPL. In C# Interactive, this can be done like so:

#r "functional-csharp-code\LaYumba.Functional\bin\Debug\netstandard1.6\LaYumba.Functional.dll"

The path above may not work for you, in which case use an absolute path to the dll, or type Directory.GetCurrentDirectory() into the REPL to see what to use as a base for a relative path.

Next, add these imports:

using LaYumba.Functional;
using static LaYumba.Functional.F;

You're now ready to experiment with functional code right in the REPL, for example:

> Func<int, int, int> plus = (a, b) => a + b;
> Some(plus).Apply(1).Apply(2)
[Some(3)]
> Some(plus).Apply(1).Apply(None)
[None]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4