✅ How to get ids from tuple list?
I have following list:
List<(string Path, DepartmentDto Department)>
All I want is call following method with departments ids as parameter:
await _subjectClient.GetByDepartmentIds();
I can do smth like this:
but it's not optimized
how to do better?10 Replies
you can't possibly care about optimization with all the other logic around it
I can
Untested but I doubt there is much to "optimize" in your example in general without sacrificing readability.
This runs in parallel to be the quickest. It might not be what you want. I'm sure there is even a "better" way for this parallel version.
then clean that up first
I don't want to call GetByDepartmentIds a lot of times
I don't know your logic behind the code though
So I would not know how to optimize it
You could change it to allow multiple ids, and return a list of results
Task<MqttResult<IList<SubjectDto>>> GetByDepartmentsIds(
IEnumerable<Guid> departmentsIds,
RequestParameters parameters = default );
it's already can do it
look, I have list of departments grouped by title
so I wanna get subjects for each department without multiple call
and without destroying grouping
now I have this: List<(string Path, DepartmentDto Department)>
I want this: List<(string Path, List<SubjectDto>)> or smth like that
_subjectClient.GetByDepartmentIds(departments.Select(d => d.Department.Id));
ah I see what you mean
well, after the call, group again on the department id of the subjectI’m probably not following well; why not use an indexed collection?
I decided to rewrite my algorithm and now everything works