DigitecGalaxus / DigitecGalaxus/Galaxus.Functional

Introduce Tap

Open
#21 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
41
Forks
13
PR merge metrics
No merged PRs in 30d

Description

When chaining `Result`'s, there is often the need to work with the results value more than once, e.g. for logging and inform some listeners. One can use the functions `Map` and `AndThen` to do that, however, we than have to return the input again, which often requires to use _heavier_ code, while with a `Tap` often a simple method group could be used.

With Tap one could write
```csharp
result
.Tap(Console.Write)
.Tap(Publish);
```
Without the same functionality looks something like this:
```csharp
result.
.Map(ok =>
{
Console.Write(ok);
return ok;
}).Map(Publish);
```

The proposed naming is inspired by [tap from rxjs](https://rxjs.dev/api/operators/tap) and can be argued because of it's simmilarity to map.

As for `Map` and `AndThen` also a `TapAsync` as well as `TapErr` and `TapErrAsync` should be introduced.

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate the existing Result Map and AndThen implementations and their tests, then trace how synchronous and asynchronous success and error flows are represented. Done means the Result API supports Tap, TapAsync, TapErr, and TapErrAsync with the chaining behavior shown in the issue and corresponding coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.