-
Notifications
You must be signed in to change notification settings - Fork 347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix isNotA filter code in ValueSet expander #2847
Fix isNotA filter code in ValueSet expander #2847
Conversation
@@ -67,27 +67,23 @@ internal static List<CSDC> RemoveCode(this ICollection<CSDC> concepts, string co | |||
|
|||
private static ICollection<CSDC> removeCodeByPredicate(this ICollection<CSDC> concepts, Predicate<CSDC> predicate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we have side effects: we remove items, but we return the collection because we want to keep the fluent syntax. We should really be making this pure, that way the signature makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are suggesting to make this a void you mean?
@@ -67,27 +67,23 @@ internal static List<CSDC> RemoveCode(this ICollection<CSDC> concepts, string co | |||
|
|||
private static ICollection<CSDC> removeCodeByPredicate(this ICollection<CSDC> concepts, Predicate<CSDC> predicate) | |||
{ | |||
foreach (var concept in concepts) | |||
var itemsToBeRemoved = concepts.Where(c => predicate(c)).ToList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We iterate 3 times now. We can get away with only doing this once, by just putting all the calls in a foreach loop, or better yet: a select (if we are going pure)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to do this in a single forloop (or linq statement), but I couldn't figure it out without duplicating collections, and making it a mess.
You have a suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case duplicating subsets of collections is a fact of life I think. The most optimized version is a big chain call, since the compiler can chain the methods together into a single loop. I will suggest a commit (once I find out how to)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, it seems like i'm not able to suggest it the way I wanted to. I would like to suggest something along the lines of:
internal static List<CSDC> RemoveCode(this ICollection<CSDC> concepts, string code)
{
return concepts.getNonMatchingCodes(c => c.Code == code);
}
private static List<CSDC> getNonMatchingCodes(this ICollection<CSDC> concepts, Predicate<CSDC> predicate)
{
var filtered = concepts.Where(c => !predicate(c)).ToList();
foreach (var concept in filtered.Where(concept => concept.Concept?.Count is > 0))
{
concept.Concept = concept.Concept.getNonMatchingCodes(predicate).ToList();
}
return filtered;
}
fixes #2801