forked from AndreyTsvetkov/Functional.Maybe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaybeSomethingNothingHelpers.cs
52 lines (49 loc) · 1.29 KB
/
MaybeSomethingNothingHelpers.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace Functional.Maybe
{
/// <summary>
/// IsSomething, IsNothing and shorthands to create typed Nothing of correct type
/// </summary>
public static class MaybeSomethingNothingHelpers
{
/// <summary>
/// Has a value inside
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <returns></returns>
public static bool IsSomething<T>(this Maybe<T> a)
{
return a.HasValue;
}
/// <summary>
/// Has no value inside
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <returns></returns>
public static bool IsNothing<T>(this Maybe<T> a)
{
return !a.IsSomething();
}
/// <summary>
/// Создает "ничто" такого же типа, как исходный объект
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="_"></param>
/// <returns></returns>
public static Maybe<T> NothingOf<T>(this Maybe<T> _)
{
return Maybe<T>.Nothing;
}
/// <summary>
/// Создает "ничто" такого же типа, как исходный объект
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="_"></param>
/// <returns></returns>
public static Maybe<T> NothingOf<T>(this T _)
{
return Maybe<T>.Nothing;
}
}
}