/// <summary> /// Gets if the two values are equal. /// </summary> /// <param name="other"> /// The compared value. /// </param> /// <returns> /// returns <c>true</c> if /// /// The two values are both existing or missing /// and inner values are equal with the default comparer. /// </returns> public bool Equals(Opt <T> other) { if (!IsSome) { return(!other.IsSome); } return(other.IsSome && EqualityComparer <T> .Default.Equals(Value, other.Value)); }
public void SomeHasValue() { var some1 = Opt.Some(1); some1.IsSome .Is(true); some1.Value .Is(1); }
public void NoneHasNoValue() { var none = Opt.None <int>(); none.IsSome .Is(false); Assert.Throws <InvalidOperationException>(() => Opt.None <string>().Value ); }
/// <summary> /// Compare the two values. /// /// <c>None</c>s are lesser than <c>Some</c>s. /// </summary> public int CompareTo(Opt <T> other) { if (!IsSome) { return(other.IsSome ? 0 : 1); } if (!other.IsSome) { return(-1); } return(Comparer <T> .Default.Compare(Value, other.Value)); }
public void ItMapsNoneToNestedSome() { Opt.AllowNull(Opt.None <int>()) .Is(Opt.Some(Opt.None <int>())); }
public void ItMapsNonnullDefaultToSome() { Opt.AllowNull(default(int)) .Is(Opt.Some(0)); }
public void ItMapsNonnullToSome() { Opt.AllowNull("not null") .Is(Opt.Some("not null")); }
public void ItMapsNullStructToNone() { Opt.AllowNull((int?)null) .Is(Opt.None <int>()); }
public void ItMapsNullReferenceToNone() { Opt.AllowNull((string)null) .Is(Opt.None <string>()); }
public void SomeRejectsNull() { Assert.Throws <ArgumentNullException>(() => Opt.Some((string)null) ); }
public Field(Opt <T> defaultValue, int index) { DefaultValue = defaultValue; Index = index; }