Using HOFs so wildly makes the code very hard to read. Is it necessary to pass validation and prompt logic as functions?
Cameron Presley
First off, thanks for looking at the snippet, we all do better if we learn together.
For the problem I was trying to solve, I believe so. In this card game simulation I'm working on, I'm asking the user to choose an opponent and/or a card as well. I originally wrote the logic for these two cases separate, but I noticed that they were very similar to one another, so I wanted to see if there were some generic way I can define how a user makes a choice and then for when asking for a card, I can load the certain functions whereas for when I'm asking for a player, I can pass different ones.
I can see your point that using HOFs can be a bit confusing, but I'm not sure what else I could've have done. I'm completely open to suggestions, so any feedback would be great.
I've never seen the function keyword before, but it looks like a combination of match with a single param. That's definitely interesting.
I've also never seen Option.tryFillWith before, but it looks like it'll take the value if it's some, otherwise, it looks like it recurses, is that correct?
Also, I'm not sure why you defined (>=>) and why that's being sued, could you elaborate a bit more on that?
Thanks
chosen breed
Hi Cameron. Thanks for sharing the code. Yeah readability could be an issue but that is can be a subjective quality ;-). I think F# gives us the power to be really expressive. With that power comes some responsibility. I think I understand what's going on. With regards to Vasily's implementation I'll let him comment :-)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.
Using HOFs so wildly makes the code very hard to read. Is it necessary to pass validation and prompt logic as functions?
First off, thanks for looking at the snippet, we all do better if we learn together.
For the problem I was trying to solve, I believe so. In this card game simulation I'm working on, I'm asking the user to choose an opponent and/or a card as well. I originally wrote the logic for these two cases separate, but I noticed that they were very similar to one another, so I wanted to see if there were some generic way I can define how a user makes a choice and then for when asking for a card, I can load the certain functions whereas for when I'm asking for a player, I can pass different ones.
I can see your point that using HOFs can be a bit confusing, but I'm not sure what else I could've have done. I'm completely open to suggestions, so any feedback would be great.
Some Questions if you have the time:
Thanks
Hi Cameron. Thanks for sharing the code. Yeah readability could be an issue but that is can be a subjective quality ;-). I think F# gives us the power to be really expressive. With that power comes some responsibility. I think I understand what's going on. With regards to Vasily's implementation I'll let him comment :-)