dev-adventures-realworld icon indicating copy to clipboard operation
dev-adventures-realworld copied to clipboard

Functional async

Open dzmitry-lahoda opened this issue 4 years ago • 1 comments

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#.

dzmitry-lahoda avatar Apr 11 '20 16:04 dzmitry-lahoda

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.

dnikolovv avatar Apr 13 '20 05:04 dnikolovv