language-ext
language-ext copied to clipboard
Suggestion: MapT async overload for Task<Option>
Discussed in https://github.com/louthy/language-ext/discussions/1013
Originally posted by MrWuffels March 25, 2022 Hi,
I'm new here and I don't know if this was suggested or discussed already, at least I didn't find anything.
I came across following "issue":
Func<string,Task<Option<string>>> bindTTest = str => Task.FromResult(Some("Haha"));
Func<string, Task<string>> mapTTest = str => Task.FromResult("haha");
var taskOption = GetTaskOption(); //returns Task<Option<string>>
var bindT = taskOption.BindT(x => bindTTest(x)); //returns Task<Option<string>>
var mapT = taskOption.MapT(x => mapTTest(x)); //returns Task<Option<Task<string>>>
As you can see in this little example, BindT returns a Task<Option
Of course I have read way to late that suggestions should be made on the issues page. Shame on me. However here we are, still the same "problem". So, maybe you have a few thoughts about this idea?
@MrWuffels The extension methods are all code-gen'd, which is why these anomalies happen (with Task extensions). It's a bit of a tangled mess, so I'd prefer to leave this until I replace the T4 templates with something smarter. I'd suggest adding an extension of your own that does what you need, or using OptionAsync
which is a type that captures optional-tasks.
Thank you for the answer. Then I'm probably going to follow your advise and just add a similar method by my own, but of course I'm looking forward to the replacement ;)
@louthy I took a quick look into your solution, because we just need the extension for a few monads. So I would like to ask if you'd allow me to add at least the few extensions we need and create a pull request, that would make our lives a bit easier. Of course I understand if this makes even less sense when this extensions only exist for a few ones, and when you like to replace the whole thing sooner or later anyway