Skip to content

Commit

Permalink
Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrwrbgs authored Aug 26, 2018
1 parent 198b0ef commit fd69b38
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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<object, NoElements> last1 = myList1.LastOrReasonWhyNot();
OneOf<object, NoElements> 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());
```

0 comments on commit fd69b38

Please sign in to comment.