Exemplo n.º 1
0
        private static void HandlingNestedOptionsWithFlatMap(decimal number, decimal firstDivisor, decimal secondDivisor)
        {
            IOption <decimal>            divisionResult         = Divide(number, firstDivisor);
            IOption <IOption <decimal> > resultOfDoubleDivision = divisionResult.Map(r => Divide(r, secondDivisor));

            // This option has value if both the inner and the outer option have value.
            IOption <decimal> flattenedResultOfDoubleDivision1 = resultOfDoubleDivision.Flatten();

            // Same can be done with 1 call.
            IOption <decimal> flattenedResultOfDoubleDivision2 = divisionResult.FlatMap(r => Divide(r, secondDivisor));
        }