Skip to content

Commit

Permalink
#50 and #49. Merged the v3.3.1 branch.
Browse files Browse the repository at this point in the history
This branch included the `HasValue` method for #49.
This branch also included the PR #50. But as `Maybe<T>` is now removed in the v8 branch, much of that PR becomes redundant and so has been removed.
  • Loading branch information
DavidArno committed Nov 26, 2018
2 parents 5d55009 + 33e0cc3 commit 1dc36c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/SuccincT/Unions/Union{T1,T2,T3,T4}.cs
Expand Up @@ -53,6 +53,23 @@ public TResult Value<TResult>()
default: throw new InvalidCaseOfTypeException(typeof(TResult));
}
}

public bool HasValue<TResult>()
{
switch (Case)
{
case Variant.Case1:
return _value1.GetType() == typeof(TResult);
case Variant.Case2:
return _value2.GetType() == typeof(TResult);
case Variant.Case3:
return _value3.GetType() == typeof(TResult);
case Variant.Case4:
return _value4.GetType() == typeof(TResult);
}

return false;
}

public Option<TResult> TryGetValue<TResult>()
{
Expand Down
15 changes: 15 additions & 0 deletions src/SuccincT/Unions/Union{T1,T2,T3}.cs
Expand Up @@ -44,6 +44,21 @@ public TResult Value<TResult>()
default: throw new InvalidCaseOfTypeException(typeof(TResult));
}
}

public bool HasValue<TResult>()
{
switch (Case)
{
case Variant.Case1:
return _value1.GetType() == typeof(TResult);
case Variant.Case2:
return _value2.GetType() == typeof(TResult);
case Variant.Case3:
return _value3.GetType() == typeof(TResult);
}

return false;
}

public Option<TResult> TryGetValue<TResult>()
{
Expand Down
7 changes: 7 additions & 0 deletions tests/SuccincT.Tests/SuccincT/Options/OptionTests.cs
Expand Up @@ -194,5 +194,12 @@ public void WhenNone_ValueOrDefaultReturnsDefault()
var option = Option<int>.None();
AreEqual(0, option.ValueOrDefault);
}

[Test]
public void WhenImplicitlyConverting_ValueEqualsProvidedParameter()
{
Option<int> option = 3;
AreEqual(3, option.Value);
}
}
}

0 comments on commit 1dc36c1

Please sign in to comment.