functional-csharp-code

所属分类:C/C++基础
开发工具:C#
文件大小:233KB
下载次数:0
上传日期:2022-12-07 16:48:25
上 传 者sh-1993
说明:  C语言中函数编程的代码示例#
(Code samples for Functional Programming in C#)

文件列表:
Boc.Domain (0, 2021-12-21)
Boc.Domain\Boc.Domain.fsproj (204, 2021-12-21)
Boc.Domain\Lib.fs (608, 2021-12-21)
Examples (0, 2021-12-21)
Examples\Chapter01 (0, 2021-12-21)
Examples\Chapter01\Circle.cs (429, 2021-12-21)
Examples\Chapter01\DbLogger (0, 2021-12-21)
Examples\Chapter01\DbLogger\ConnectionHelper.cs (954, 2021-12-21)
Examples\Chapter01\DbLogger\DbLogger_V1.cs (1219, 2021-12-21)
Examples\Chapter01\DbLogger\DbLogger_V2.cs (804, 2021-12-21)
Examples\Chapter01\DbLogger\LogMessage.cs (71, 2021-12-21)
Examples\Chapter01\DbLogger\TimeSpanExt.cs (452, 2021-12-21)
Examples\Chapter01\Employee.cs (87, 2021-12-21)
Examples\Chapter01\Functions.cs (870, 2021-12-21)
Examples\Chapter01\HOFs.cs (500, 2021-12-21)
Examples\Chapter01\Tenets.cs (1546, 2021-12-21)
Examples\Chapter02 (0, 2021-12-21)
Examples\Chapter02\Boc (0, 2021-12-21)
Examples\Chapter02\Boc\BicExistsValidator.cs (1395, 2021-12-21)
Examples\Chapter02\Boc\Commands.cs (688, 2021-12-21)
Examples\Chapter02\Boc\DateNotPastValidator.NotTestable.cs (712, 2021-12-21)
Examples\Chapter02\Boc\DateNotPastValidator.TestableWithInjectedValue.cs (365, 2021-12-21)
Examples\Chapter02\Boc\DateNotPastValidator.TestableWithInterface.cs (1876, 2021-12-21)
Examples\Chapter02\Boc\IValidator.cs (98, 2021-12-21)
Examples\Chapter02\ListFormatter (0, 2021-12-21)
Examples\Chapter02\ListFormatter\ListFormatter_InfiniteSequence.cs (1453, 2021-12-21)
Examples\Chapter02\ListFormatter\ListFormatter_Instance.cs (1619, 2021-12-21)
Examples\Chapter02\ListFormatter\ListFormatter_ParNaive.cs (1845, 2021-12-21)
Examples\Chapter02\ListFormatter\ListFormatter_ParZip.cs (1038, 2021-12-21)
Examples\Chapter02\ListFormatter\ListFormatter_Static.cs (1796, 2021-12-21)
Examples\Chapter02\ListFormatter\ListFormatter_Zip.cs (668, 2021-12-21)
Examples\Chapter02\ListFormatter\Numbered.cs (435, 2021-12-21)
Examples\Chapter02\ListFormatter\StringExt.cs (184, 2021-12-21)
Examples\Chapter02\MutatingArguments.cs (972, 2021-12-21)
Examples\Chapter02\Zip.cs (437, 2021-12-21)
Examples\Chapter03 (0, 2021-12-21)
Examples\Chapter03\Age.cs (2112, 2021-12-21)
Examples\Chapter03\ConfigurationExt.cs (1460, 2021-12-21)
... ...

# Functional Programming in C# # This repo contains the code samples, exercises and solutions for the book [Functional Programming in C#](https://www.manning.com/books/functional-programming-in-c-sharp?a_aid=functional-programming-in-c-sharp&a_bid=ad9af506) published by Manning. [![Functional Programming in C#](cover.jpg)](https://www.manning.com/books/functional-programming-in-c-sharp?a_aid=functional-programming-in-c-sharp&a_bid=ad9af506) The code samples are organized in the following projects: - **Examples**: examples used throughout the book, by chapter - **Exercises**: placeholders for you to do the exercises, compile and run them; and compare to the provided solutions - **LaYumba.Functional**: a functional library that we develop throughout the book - **LaYumba.Functional.Data**: very simple functional data structures discussed in Chapter 9 - **LaYumba.Functional.Tests**: also illustrative of topics explained in the book, and useful to better understand the constructs in the library - **Boc.Domain**: an example of using F# for domain objects **Note:** you are welcome to reference `LaYumba.Functional` from your projects via [NuGet](https://www.nuget.org/packages/LaYumba.Functional), and submit PRs with improvements, but the main intent of this library is pedagogical. For a more fully-fledged functional library, consider [LanguageExt](https://github.com/louthy/language-ext) ## 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. ### Prerequisites - [.NET Core 2.0.3 SDK](https://www.microsoft.com/net/download/core) To check this is available, type `dotnet --version` at the command prompt, and you should get `2.0.3` or greater ### One-time setup ``` $ git clone git@github.com:la-yumba/functional-csharp-code.git $ cd functional-csharp-code $ dotnet restore ``` ### Running the tests 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. ### Running examples 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` ## Setting up the REPL Throughout the book, I encourage readers to try things out in the [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). - If you use Visual Studio, you can start the REPL by going to `View > Other Windows > C# Interactive` (short tutorial [here](https://github.com/dotnet/roslyn/wiki/C%23-Interactive-Walkthrough)) - On Mono, use the `csharp` command - There are several other REPLs available, some even run in the browser You'll often need to import `LaYumba.Functional` in the REPL. In C# Interactive, this can be done like so: ```csharp #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: ```csharp using LaYumba.Functional; using static LaYumba.Functional.F; ``` You're now ready to experiment with functional code right in the REPL, for example: ```csharp > Func plus = (a, b) => a + b; > Some(plus).Apply(1).Apply(2) [Some(3)] > Some(plus).Apply(1).Apply(None) [None] ``` ## Doing the exercises - edit the code in `Exercises` as needed - edit `Exercises/Program.cs` to start the class you want - run it with: ``` $ cd Exercises $ dotnet run ``` - run your tests: ``` $ cd Exercises $ dotnet test ```

近期下载者

相关文件


收藏者