-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
29 lines (19 loc) · 708 Bytes
/
Program.cs
File metadata and controls
29 lines (19 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using static MaybeFactory;
// Based on the article "Understand monads with LINQ" (http://codewithstyle.info/understand-monads-linq/)
class Program
{
static void Main(string[] args)
{
// Maybe.Select
Maybe<int> age = Some(27);
Maybe<string> result = from x in age select $"I'm {x} years old";
Console.WriteLine(result.Value);
var empty = from x in None<int>() select "test";
Console.WriteLine(empty.HasValue);
// Maybe.SelectMany
var person = new Person { Name = "John" };
var monadicPerson = Some(new MonadicPerson { Name = "Jack"});
monadicPerson.GetSupervisorName();
}
}