dev-adventures-realworld
dev-adventures-realworld copied to clipboard
Functional async
What do you think about replacing things like:
public async Task<IActionResult> Get() =>
Ok(new { tags = await _tagsService.GetAllAsync() });
to (whatever works)
// use injection to see direct dependencies in each method
public Task<IActionResult> Get([FromServices]ITagsService service) =>
service
.GetAllAsync()
.Ok(tags => new { tags = tags});
// service
// .GetAllAsync()
// .Next(tags =>Ok(new { tags = tags}));
So to speak it is possible to avoid await
keyword(and still be async) in most cases and use pipelining. Looks like F#.
As much as I like this approach, I think it's just going too far. I was kind of trying to find the balance between the standard (already familiar to most) and functional way of doing things. Sadly(?), C# is not a functional language, so I think it's better we stick to the "basics" where there's no obvious benefit of doing it functionally.