From c6bd0ee26fc185870d4b7996544eceed496e2dea Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sat, 24 Oct 2015 20:55:54 -0400 Subject: [PATCH] clean up readme --- Readme.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Readme.md b/Readme.md index 9e10465..147c05a 100644 --- a/Readme.md +++ b/Readme.md @@ -4,12 +4,21 @@ This adds some extra linq extensions I have found in the ruby community. Ruby de ## Reject Reject works much like a `.WhereNot` Basically a linq method where things that return true will be exlcuded from the Returning IEnumerable. This is handy as sometimes you end up with a `Where` statement that basically says where not this and not that and not this other thing. Sometimes its easier to say reject this. +`List.Reject(a=>a.IShouldntBeHere)` + +this is the same as writing + +`List.Where(a=>a.IShouldntBeHere == false)` ## Cycle Cycle will run an action for every element in an IEnumerable. This will run forever unless you pass the number of times to enumerate over the array +`Enumerable.Range(1,4).Cycle(a=>Console.Write(a + ","),2);` + +this will print `1,2,3,4,1,2,3,4` + ## ForEach I hope I dont have to explain this one. `ListOfThings.ForEach(a=>a.DoSomething())` @@ -26,3 +35,15 @@ Compact removes all nulls from a list. its a simplification of `.Where(a=>a!=nul This one is the most complex. This works on Enumerable of Enumerables. Basically pass in an expected object. If that object lives in one of the child arrays that child array is returned. Otherwise return nothing. +```csharp + + +var outer = new List>(); + outer.Add(new List() { "books", "school", "apple", "playtime" }); + outer.Add(new List() { "star", "wars", "vader" }); + var assc = outer.AssocFirstOrDefault("wars"); +//assc will be the 2nd list + + +``` +