From fd69b38447a71e5a272279e91ff47173889f04ce Mon Sep 17 00:00:00 2001 From: ndrwrbgs Date: Sun, 26 Aug 2018 10:11:52 -0700 Subject: [PATCH] Create README.md --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..612e7b9 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# OneOf.Linq + +Extensions for https://github.com/mcintyre321/OneOf that expose `XOrResonWhyNot` extension methods for LINQ. + +# Demonstration + +Without library: +```C# +var myList1 = new object[] { 1, null }; +var myList2 = new object[] { }; + +object last1 = myList1.LastOrDefault(); +object last2 = myList2.LastOrDefault(); + +// Oh no! This fails because both are null! +// Even worse when you have value types (like int) and +// can't tell the difference between 0 and 'no-values' +Assert.AreNotEqual(last1, last2, "because one had a last and one did not"); +``` + +With library: +```C# +var myList1 = new object[] { 1, null }; +var myList2 = new object[] { }; + +OneOf last1 = myList1.LastOrReasonWhyNot(); +OneOf last2 = myList2.LastOrReasonWhyNot(); + +// Yay! it works! +Assert.AreNotEqual(last1, last2, "because one had a last and one did not"); + +Assert.IsTrue(last1.HasValue()); +Assert.IsFalse(last2.HasValue()); + +Assert.AreEqual(null, last1.Value()); +Assert.AreEqual(default(NoElements), last2.WhyNot()); +```