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()); }
public void Map() { Assert.Equal(45, Success.Map(i => i + 3).Get()); Assert.True(Error.Map(i => i + 3).IsError); }
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)); }