Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate multiple options #73

Open
KaliCZ opened this issue Apr 1, 2021 · 0 comments
Open

Aggregate multiple options #73

KaliCZ opened this issue Apr 1, 2021 · 0 comments

Comments

@KaliCZ
Copy link
Contributor

KaliCZ commented Apr 1, 2021

Just like Try.Aggregate except with options. if all options have value, return an option with all the values.
I would expect 2 overloads:

  • One returning a tuple of all the option values
  • One with a parameter for a function to map the tuple into a TResult.

I would expect overloads for 2 3 4 5 6 options (go up to 9 if you want)

Example signature:

public static IOption<Tuple<T1, T2>> Aggregate<T1, T2>(IOption<T1>option1, IOption<T2>option2)
{
    return option1.Flatmap(v1 => option2.Map(v2 => Tuple.Create(v1, v2)));
}

and

public static IOption<T> Aggregate<T, T1, T2>(IOption<T1>option1, IOption<T2>option2, Func<T1, T2, T> func)
{
    return Aggregate(option1, option2).Map(tuple => func(tuple.Item1, tuple.Item2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants