DavidArno / SuccincT

Discriminated unions, pattern matching and partial applications for C#
MIT License
266 stars 15 forks source link

Option Extensions #20

Closed megafinz closed 7 years ago

megafinz commented 7 years ago

Added a couple of extensions for Options.

1) ToOption is a shortcut to convert nullable values that come from external APIs.

2) Map is a way to apply a given function to the value of Option.

3) AsNullable is a shortcut to convert Option with struct value into a nullable struct that external APIs may use.

4) Or is a way to allow expressions like F1() ?? F2() ?? F3() to be used in the world of Options.

5) Flatten is a way to extract a nested Option, which is useful when you operate on a collection of Options with stuff like TryFirst.

6) Choose is a way to extract values from a collection of Options.

DavidArno commented 7 years ago

Thanks @megafinz, this all looks really good. You even wrote tests! ❤️

I think I'll merge this and then copy it over to a new v2_3 branch as its features that can be published soon, rather than waiting for VS2017 to go live and and my planned v3 release.