-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStatus.cs
93 lines (61 loc) · 2.28 KB
/
Status.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
namespace Activ.Rx{
public readonly struct status{
readonly int ω;
public static readonly status done = new status(+1),
fail = new status(-1),
cont = new status( 0);
public bool failing => ω == -1;
public bool running => ω == 0;
public bool complete => ω == +1;
// -------------------------------------------------------------------
// Public for testing purposes (transitional)
public status(int ω)
=> this.ω = ω >= -1 || ω <= +1 ? ω
: throw new ArgumentException($"Init value out of bounds {ω}");
// -------------------------------------------------------------------
// Sequence/Selector
public static status operator & (status x, status y)
=> y;
public static status operator | (status x, status y)
=> y;
public static bool operator true (status s)
=> s.ω != -1;
public static bool operator false (status s)
=> s.ω != +1;
// Other operators
public static status operator + (status x, status y)
=> new status(Math.Max(x.ω, y.ω));
public static status operator * (status x, status y)
=> new status(Math.Min(x.ω, y.ω));
public static status operator % (status x, status y)
=> new status(x.ω);
public static status operator ! (status s)
=> new status(-s.ω);
public static status operator ~ (status s)
=> new status(s.ω * s.ω);
public static status operator + (status s)
=> new status(s.ω == +1 ? +1 : s.ω + 1);
public static status operator - (status s)
=> new status(s.ω == -1 ? -1 : s.ω - 1);
public static status operator ++ (status s)
=> +s;
public static status operator -- (status s)
=> -s;
// Type conversions
public static implicit operator status(bool that)
=> new status(that ? +1 : -1);
// Equality and hashing
public override bool Equals(object x)
=> x is status ? Equals((status)x) : false;
public bool Equals(status x)
=> this == x;
public static bool operator == (status x, status y)
=> x.ω == y.ω;
public static bool operator != (status x, status y)
=> !(x == y);
public override int GetHashCode()
=> ω;
public override string ToString()
=> ω.ToString();
}}