Exemplo n.º 1
0
 private void TransformingSuccessWithMap()
 {
     ITry <int, NetworkOperationError>     number            = Api.GetNumber();
     ITry <decimal, NetworkOperationError> castedNumber      = number.Map(r => (decimal)r);
     ITry <string, NetworkOperationError>  stringifiedNumber = number.Map(r => r.ToString());
 }
Exemplo n.º 2
0
        public void Map()
        {
            Assert.Equal(45, Success.Map(i => i + 3).Get());

            Assert.True(Error.Map(i => i + 3).IsError);
        }
Exemplo n.º 3
0
        private void HandlingNestedTriesWithFlatMap()
        {
            ITry <int, NetworkOperationError> number = Api.GetNumber();
            ITry <ITry <int, NetworkOperationError>, NetworkOperationError> doubleNumber = number.Map(r => Api.DoubleNumber(r));

            // This try succeeds only if both tries succeed. However the second lambda is only executed in case the first try is successful.
            ITry <int, NetworkOperationError> doubleNumberFlattened = number.FlatMap(r => Api.DoubleNumber(r));
        }