-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
37 lines (31 loc) · 963 Bytes
/
Program.cs
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
29
30
31
32
33
34
35
36
37
using Optional;
using System;
using System.Linq;
namespace optional_of_t
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("This program showcases multiple usages of the Optional<T> type for a more functional programming style");
var api = new ItemApi(new());
api.GetItem(99).Match(
some => Console.WriteLine($"Got an item: {some}"),
() => Console.WriteLine("Oops, we missed!")
);
foreach (var item in api.GetItems(100))
{
Console.WriteLine(item);
}
var optionals = new Option<string>[]
{
"test".Some(),
"test".None()
};
foreach (var item in optionals.SelectMany(o => o.ToEnumerable()))
{
Console.WriteLine(item);
}
}
}
}