# 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<int, int, int> 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
```
没有合适的资源?快使用搜索试试~ 我知道了~
Code samples for Functional Programming in C#.zip
共239个文件
cs:222个
csproj:5个
json:2个
需积分: 5 0 下载量 44 浏览量
2024-01-05
14:16:38
上传
评论
收藏 205KB ZIP 举报
温馨提示
Code samples for Functional Programming in C#
资源推荐
资源详情
资源评论
收起资源包目录
Code samples for Functional Programming in C#.zip (239个子文件)
web.config 552B
NuGet.Config 286B
TreeNumbering.cs 18KB
Option.cs 7KB
TaskExt.cs 7KB
Validation.cs 6KB
OptionTest.cs 6KB
PhoneNumber.cs 6KB
Valid.cs 6KB
Tests.cs 6KB
Task.cs 6KB
Either.cs 5KB
CurrencyLookup.cs 5KB
Solutions.cs 5KB
Exceptional.cs 5KB
Solutions.cs 5KB
IEnumerable.cs 4KB
F.cs 4KB
EnumerableExt.cs 4KB
OptionExamples.cs 4KB
Agent.cs 4KB
FuncExtTest.cs 4KB
Startup.cs 4KB
CurrencyLookup.cs 4KB
CurrencyLookup.cs 4KB
ControllerActivator.cs 4KB
DbLogger.cs 4KB
Trade.cs 4KB
Free.cs 3KB
LinkedList.cs 3KB
TaskValidationMonad.cs 3KB
Bst.cs 3KB
ApplicativeLaws.cs 3KB
Generator.cs 3KB
Controller.cs 3KB
Solutions.cs 3KB
ValidationStrategies.cs 3KB
Applicative.cs 3KB
Middleware.cs 3KB
FuncExt.cs 3KB
Solutions.cs 3KB
AccountRegistry.cs 3KB
Solutions.cs 3KB
Solutions.cs 3KB
Monkeys.cs 3KB
Operators.cs 3KB
OptionT.cs 3KB
Controller.cs 3KB
CurrencyLookup.cs 3KB
Account_Imutable.cs 2KB
BinaryTree.cs 2KB
ValidationStrategies.cs 2KB
AccountStatement.cs 2KB
Controller.cs 2KB
Exercises.cs 2KB
ObservableExt.cs 2KB
Exercises.cs 2KB
VoidContinuations.cs 2KB
Exercises.cs 2KB
Age.cs 2KB
Traversables.cs 2KB
Account.cs 2KB
Solutions.cs 2KB
Errors.cs 2KB
BookTransferController.cs 2KB
Solutions.cs 2KB
Account.cs 2KB
MakeTransferController.cs 2KB
StatefulComputation.cs 2KB
Pattern.cs 2KB
Solutions.cs 2KB
DateNotPastValidator.TestableWithInterface.cs 2KB
Option.cs 2KB
CreatingObservables.cs 2KB
ListFormatter_ParNaive.cs 2KB
ListFormatter_Static.cs 2KB
TypeInference.cs 2KB
MonadLaws.cs 2KB
MonadLaws.cs 2KB
Reader.cs 2KB
Introductory.cs 2KB
Functional.cs 2KB
ControllerActivator.cs 2KB
ListNumbering.cs 2KB
ListFormatter_Instance.cs 2KB
MapBinaryFuncExample.cs 2KB
Greetings.cs 2KB
Tenets.cs 2KB
Program.cs 1KB
Earnings.cs 1KB
Validation.cs 1KB
Try.cs 1KB
Exercises.cs 1KB
Instrumentation.cs 1KB
ConfigurationExt.cs 1KB
ListFormatter_InfiniteSequence.cs 1KB
Exercises.cs 1KB
Try.cs 1KB
Controller.cs 1KB
BicExistsValidator.cs 1KB
共 239 条
- 1
- 2
- 3
资源评论
Lei宝啊
- 粉丝: 1931
- 资源: 1331
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功