You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two lists of objects. I want to loop though the first list and see if there are any matches in the second list, based on multiple fields, and I'd like to use a method which returns a bool to do the logic. However, I don't know if that will be possible. For the items in the first list that I'm looping through, when there is a match, I want to add the index to a list, building up a list of the indices which match.
I know that you can look at an IEnumerable in LINQ and get back a list of indexes based on matches, but I'm not sure if that is the way to do this. For example:
myarray
.Select((p, i) => new { Item = p, Index = i })
.Where(p => SomeCondition(p.Item))
.Select(p => p.Index);
With the list of indexes that is created, I want to add those numbers to an object which will be output in the "Then()" Let me try and show this in pseudo code. In this example, let's say there are 10 objects in each of the lists, and there items 0, 2, and 7 match.
public override void Define()
{
ListOfObjects inbound; // fact in memory with 10 objects
ListOfObjects outbound; // fact in memory with 10 objects
List matchingIndexes; // for storing the indexes of objects that match
OutputObject outputObject; // do store output data based on indexes
When()
.Match(() => inbound, some criteria) // get list of objects--this already works in my code
.Match(() => outbound, some other criteria) // get list of objects--this already works in my code
// Loop through inbound and for each matching item in outbound, add inbound's array index to "matchingIndexes".
// Should looping occur here or in "DoSomeLogic"? Maybe it makes sense to do all the looping and logic
// in "DoSomeLogic()" and have that return the list of indexes, but how do I assign that
// value to "matchingIndexes"?
.Match/Query/Whatever(() => matchingIndexes, DoSomeLogic(inbound, outbound))
Then()
.Do(ctx => outputObject.ProcessMatchingIndexes(matchingIndexes))
}
"matchingIndexes" should contain a list of 3 integers: 0, 2, and 7. "outputObject.ProcessMatchingIndexes" will receive that list at a parameter and do some things with those numbers.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have two lists of objects. I want to loop though the first list and see if there are any matches in the second list, based on multiple fields, and I'd like to use a method which returns a bool to do the logic. However, I don't know if that will be possible. For the items in the first list that I'm looping through, when there is a match, I want to add the index to a list, building up a list of the indices which match.
I know that you can look at an IEnumerable in LINQ and get back a list of indexes based on matches, but I'm not sure if that is the way to do this. For example:
myarray
.Select((p, i) => new { Item = p, Index = i })
.Where(p => SomeCondition(p.Item))
.Select(p => p.Index);
With the list of indexes that is created, I want to add those numbers to an object which will be output in the "Then()" Let me try and show this in pseudo code. In this example, let's say there are 10 objects in each of the lists, and there items 0, 2, and 7 match.
public override void Define()
{
ListOfObjects inbound; // fact in memory with 10 objects
ListOfObjects outbound; // fact in memory with 10 objects
List matchingIndexes; // for storing the indexes of objects that match
OutputObject outputObject; // do store output data based on indexes
}
"matchingIndexes" should contain a list of 3 integers: 0, 2, and 7. "outputObject.ProcessMatchingIndexes" will receive that list at a parameter and do some things with those numbers.
Beta Was this translation helpful? Give feedback.
All reactions