Skip to content

Commit

Permalink
Value of Optinal is private instead of internal
Browse files Browse the repository at this point in the history
  • Loading branch information
duffleit committed Dec 1, 2016
1 parent 14a9989 commit 3558f51
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions fluentOptionals/Composition/CompositeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ public static bool IsSome<T>(this Optional<T> optional)
{
return optional.Match(_ => true, False);
}

public static T ValueOrDefault<T>(this Optional<T> optional)
{
return optional.ValueOr(default(T));
}
}
}
4 changes: 2 additions & 2 deletions fluentOptionals/Composition/Optional2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ internal Optional(Optional<T1> o1, Optional<T2> o2)
public void Match(Action<T1, T2> some, Action none)
{
if (IsSome)
some(_o1.Value, _o2.Value);
some(_o1.ValueOrDefault(), _o2.ValueOrDefault());
else
none();
}

public TReturn Match<TReturn>(Func<T1, T2, TReturn> some, Func<TReturn> none)
=> IsSome
? some(_o1.Value, _o2.Value)
? some(_o1.ValueOrDefault(), _o2.ValueOrDefault())
: none();

public void IfSome(Action<T1, T2> handle)
Expand Down
4 changes: 2 additions & 2 deletions fluentOptionals/Composition/Optional3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ internal Optional(Optional<T1> o1, Optional<T2> o2, Optional<T3> o3)
public void Match(Action<T1, T2, T3> some, Action none)
{
if (IsSome)
some(_o1.Value, _o2.Value, _o3.Value);
some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault());
else
none();
}

public TReturn Match<TReturn>(Func<T1, T2, T3, TReturn> some, Func<TReturn> none)
=> IsSome
? some(_o1.Value, _o2.Value, _o3.Value)
? some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault())
: none();

public void IfSome(Action<T1, T2, T3> handle)
Expand Down
4 changes: 2 additions & 2 deletions fluentOptionals/Composition/Optional4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ internal Optional(Optional<T1> o1, Optional<T2> o2, Optional<T3> o3, Optional<T4
public void Match(Action<T1, T2, T3, T4> some, Action none)
{
if (IsSome)
some(_o1.Value, _o2.Value, _o3.Value, _o4.Value);
some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault());
else
none();
}

public TReturn Match<TReturn>(Func<T1, T2, T3, T4, TReturn> some, Func<TReturn> none)
=> IsSome
? some(_o1.Value, _o2.Value, _o3.Value, _o4.Value)
? some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault())
: none();

public void IfSome(Action<T1, T2, T3, T4> handle)
Expand Down
4 changes: 2 additions & 2 deletions fluentOptionals/Composition/Optional5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ internal Optional(Optional<T1> o1, Optional<T2> o2, Optional<T3> o3, Optional<T4
public void Match(Action<T1, T2, T3, T4, T5> some, Action none)
{
if (IsSome)
some(_o1.Value, _o2.Value, _o3.Value, _o4.Value, _o5.Value);
some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault(), _o5.ValueOrDefault());
else
none();
}

public TReturn Match<TReturn>(Func<T1, T2, T3, T4, T5, TReturn> some, Func<TReturn> none)
=> IsSome
? some(_o1.Value, _o2.Value, _o3.Value, _o4.Value, _o5.Value)
? some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault(), _o5.ValueOrDefault())
: none();

public void IfSome(Action<T1, T2, T3, T4, T5> handle)
Expand Down
4 changes: 2 additions & 2 deletions fluentOptionals/Composition/Optional6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ internal Optional(Optional<T1> o1, Optional<T2> o2, Optional<T3> o3, Optional<T4
public void Match(Action<T1, T2, T3, T4, T5, T6> some, Action none)
{
if (IsSome)
some(_o1.Value, _o2.Value, _o3.Value, _o4.Value, _o5.Value, _o6.Value);
some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault(), _o5.ValueOrDefault(), _o6.ValueOrDefault());
else
none();
}

public TReturn Match<TReturn>(Func<T1, T2, T3, T4, T5, T6, TReturn> some, Func<TReturn> none)
=> IsSome
? some(_o1.Value, _o2.Value, _o3.Value, _o4.Value, _o5.Value, _o6.Value)
? some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault(), _o5.ValueOrDefault(), _o6.ValueOrDefault())
: none();

public void IfSome(Action<T1, T2, T3, T4, T5, T6> handle)
Expand Down
4 changes: 2 additions & 2 deletions fluentOptionals/Composition/Optional7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ internal Optional(Optional<T1> o1, Optional<T2> o2, Optional<T3> o3, Optional<T4
public void Match(Action<T1, T2, T3, T4, T5, T6, T7> some, Action none)
{
if (IsSome)
some(_o1.Value, _o2.Value, _o3.Value, _o4.Value, _o5.Value, _o6.Value, _o7.Value);
some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault(), _o5.ValueOrDefault(), _o6.ValueOrDefault(), _o7.ValueOrDefault());
else
none();
}

public TReturn Match<TReturn>(Func<T1, T2, T3, T4, T5, T6, T7, TReturn> some, Func<TReturn> none)
=> IsSome
? some(_o1.Value, _o2.Value, _o3.Value, _o4.Value, _o5.Value, _o6.Value, _o7.Value)
? some(_o1.ValueOrDefault(), _o2.ValueOrDefault(), _o3.ValueOrDefault(), _o4.ValueOrDefault(), _o5.ValueOrDefault(), _o6.ValueOrDefault(), _o7.ValueOrDefault())
: none();

public void IfSome(Action<T1, T2, T3, T4, T5, T6, T7> handle)
Expand Down
18 changes: 9 additions & 9 deletions fluentOptionals/Optional.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ internal Optional(T value)
throw SomeCreationWithNullException.FromType<T>();

_isSome = true;
Value = value;
_value = value;
}

public static implicit operator Optional<T>(T value) => Optional.From(value);

private readonly bool _isSome;
internal readonly T Value;
private readonly T _value;

public void Match(Action<T> some, Action none)
{
if (_isSome)
some(Value);
some(_value);
else
none();
}

public TReturn Match<TReturn>(Func<T, TReturn> some, Func<TReturn> none)
=> _isSome ? some(Value) : none();
=> _isSome ? some(_value) : none();

public void IfSome(Action<T> handle) => Match(handle, () => { });

Expand All @@ -80,7 +80,7 @@ public TReturn Match<TReturn>(Func<T, TReturn> some, Func<TReturn> none)
public T ValueOrThrow(Exception exception)
{
if (!_isSome) throw exception;
return Value;
return _value;
}

public Optional<T, T2> Join<T2>(T2 valueToJoin)
Expand All @@ -97,17 +97,17 @@ public Optional<T, T2> Join<T2>(Optional<T2> optionalToJoin)
public int CompareTo(Optional<T> other)
=> !_isSome && !other._isSome
? 0 : _isSome && other._isSome
? Comparer<T>.Default.Compare(Value, other.Value)
? Comparer<T>.Default.Compare(_value, other._value)
: _isSome ? -1 : 1;

public int CompareTo(T other)
=> !_isSome ? -1 : Comparer<T>.Default.Compare(Value, other);
=> !_isSome ? -1 : Comparer<T>.Default.Compare(_value, other);

public bool Equals(Optional<T> other)
=> !_isSome && !other._isSome || _isSome && other._isSome && EqualityComparer<T>.Default.Equals(Value, other.Value);
=> !_isSome && !other._isSome || _isSome && other._isSome && EqualityComparer<T>.Default.Equals(_value, other._value);

public bool Equals(T other)
=> _isSome && EqualityComparer<T>.Default.Equals(Value, other);
=> _isSome && EqualityComparer<T>.Default.Equals(_value, other);

#endregion
}
Expand Down

0 comments on commit 3558f51

Please sign in to comment.