Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor changes to the maybe API

  • Loading branch information...
commit 47336318dc9bca56ca64c6712bb20b37f2cd95ed 1 parent 90c96da
@flq authored
View
15 DynamicXaml/Extensions/MaybeExtensions.cs
@@ -16,8 +16,14 @@ public static class MaybeExtensions
return @object.HasValue ? new Maybe<T>(@object.Value) : Maybe<T>.None;
}
+ [Obsolete("Please use GetValue for getting the value or a provided default")]
public static T MustHaveValue<T>(this Maybe<T> @object, T defaultValue)
{
+ return @object.GetValue(defaultValue);
+ }
+
+ public static T GetValue<T>(this Maybe<T> @object, T defaultValue)
+ {
return !@object ? defaultValue : @object.Value;
}
@@ -77,6 +83,15 @@ public static Maybe<T> Do<T>(this Maybe<T> value, Action<T> action)
return value ? map(value.Value) : Maybe<U>.None;
}
+ /// <summary>
+ /// Returns false if either the Maybe has no value (None), or
+ /// if the condition returns false;
+ /// </summary>
+ public static bool Is<T>(this Maybe<T> value, Func<T,bool> condition)
+ {
+ return value.HasValue && condition(value.Value);
+ }
+
public static Maybe<T> Or<T>(this Maybe<T> value, Maybe<T> orValue)
{
if (value.HasValue)
View
2  XamlTags.Tests/MaybeTests.cs
@@ -68,7 +68,7 @@ public void chain_and_die_when_requested()
public void choose_default_if_none()
{
string s = null;
- s.ToMaybe().MustHaveValue("foo").Should().Be("foo");
+ s.ToMaybe().GetValue("foo").Should().Be("foo");
}
[Test]
Please sign in to comment.
Something went wrong with that request. Please try again.