-
I am wondering if there is a better solution for making nested API calls than the one that I have figured out. I would love some help on finding a good pattern. Here is a simplified working example of my current code structure https://dotnetfiddle.net/nqGftc Explanation of code and what I am trying to accomplish: I don't love it. I wish it was easier to understand what the code is doing from a glance. I think it would help if the code could be changed to use more of the fluent nature of this library. The problem seems to come from needing the semantic "for each" functionally that LINQ methods offer. This isn't the first time I have struggled to make clean looking code that uses LINQ methods that have lambdas that return a Maybe I need to un-nest the Api calls/for loops and make it two separate loops? Perhaps that would be more functional? Another thought I had was that I am using too many Anyway, I am guessing I am not the only one that has needed LINQ for nested for loops and wanted to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There aren't that many methods in the library that work with collections, so adding additional ones is probably the best way forward. The Regarding retries. I wouldn't do those retries separately and instead would do them inside the same method that adds a person/pet. This way, you can control the # of retries and it's just cleaner this way because you aren't stopping working on an object until you are completely done with it. This means that you would still need to introduce wrapper methods, so maybe your current approach is the best one after all. |
Beta Was this translation helpful? Give feedback.
There aren't that many methods in the library that work with collections, so adding additional ones is probably the best way forward. The
BindSelect
you proposed looks good, but, since the library takes naming conventions from F#, it should beBindMap
(orMapBind
) instead.Regarding retries. I wouldn't do those retries separately and instead would do them inside the same method that adds a person/pet. This way, you can control the # of retries and it's just cleaner this way because you aren't stopping working on an object until you are completely done with it. This means that you would still need to introduce wrapper methods, so maybe your current approach is the best one after all.