5 public readonly static Maybe
<T
> Nothing
= new Maybe
<T
> ();
6 public T Value { get; private set; }
7 public bool HasValue { get; private set; }
12 public Maybe (T
value)
18 public override string ToString ()
21 return Value
.ToString ();
25 public Maybe
<U
> SelectMany
<U
> (Func
<T
, Maybe
<U
>> k
)
28 return Maybe
<U
>.Nothing
;
32 public Maybe
<V
> SelectMany
<U
, V
> (
33 Func
<T
, Maybe
<U
>> selector
,
34 Func
<T
, U
, V
> resultSelector
)
37 return Maybe
<V
>.Nothing
;
38 Maybe
<U
> n
= selector (Value
);
40 return Maybe
<V
>.Nothing
;
41 return resultSelector (Value
, n
.Value
).ToMaybe ();
45 static class MaybeExtensions
47 public static Maybe
<T
> ToMaybe
<T
> (this T
value)
49 return new Maybe
<T
> (value);
55 public static void Main ()
58 from x
in 1.ToMaybe ()
59 from y
in 2.ToMaybe ()
60 from z
in 3.ToMaybe ()