Lists
All methods are under the Perigee.Extensions
namespace
MatchToList
This handy method uses several de-duplication methods, as well as the Soundex and Levenshtein algorithms to produce a best-guess match between two different lists.
It will always match A => B. Meaning items that items in A will only attempt matches to items in B, not the other way around.
In the below example, Peech
is matched to PeachJuice
even though it's misspelled and Agave
has no match. Every other item is matched with it's equivalent juice.
MatchToList (Dictionary)
This version of list matching is almost identical to what is listed above, the main difference is that your input dictionary defines the keys to match, and the value is a comma separated list of additional "hints" to match by.
In this example, we can match the key Apple
with Appljuise
, because of the additional hints supplied by the dictionary.
Notice we also supplied 3, true
?
3
Means that our distance should be less than or equal to 3 edits. There are some additional preprocessing that occurs to attempt to reduce prefix and postfix content, this distance is applied and checked after.true
meansMonoMatch
is turned on, disallowing the same "list" item to be matched with multiple Keys from my dictionary. If this wasfalse
, you could have the same list item matched with as many keys as it matched!
MatchToList_Quality
If you're attempting to debug your list matching and want to understand the match values being returned by this, use the _Quality function. It will return a rich object that is easy to read showing the matched value for each key.
JoinBy
Takes every item in a list and joins it with the delimiter
DistinctBy
Works identically to the classic LINQ Distinct, however it works on classes as well.
ToDataTable
Sometimes you have a list of classes, and need to convert it to a table. This uses reflection to perform the conversion.
WhereSubclassOfType<T>
Enable you to filter a list of classes that conform to the subclass of another class
Flatten<T,R>
Recursively flatten a data structure and return the new type
FromHierarchy<T>
Recursively select down a tree until something is null. Great for returning a list of all inner exceptions in order.
RemoveDuplication
Our first example was a bunch of fruit juices. The remove duplication method attempts to find any common pattern in the list of items and remove them.
Last updated