nlkl / Optional

A robust option type for C#
MIT License
903 stars 73 forks source link

Add Combine function to maybe type. #60

Closed lbragaglia closed 4 years ago

lbragaglia commented 6 years ago

Provides a Combine function to merge two optionals (sometimes called "concat" or "append" or "aggregate" in other functional libraries).

This is an example of usage in a solution of the FizzBuzz Kata.

Can be used on enumerable of optionals with Aggregate() in this way:

listOfStrings.Aggregate((a, b) => a.Combine(b, (x, y) => x + y))
nlkl commented 5 years ago

Hi!

I will need to consider this one a bit.

On one hand I can see some cases where this could be useful, but on the other hand I belive 80% of the time this would be more readable using the query syntax available today - and I would prefer not to add extra methods unless there is clear value in doing so.

/ Nils

nlkl commented 4 years ago

Closing this one for now, as I have decided not to include it in the API for now. Feel free to open an issue, where we can discuss it further.