-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Functional Programming with C#
By :

Instead of dealing with exceptions after they occur, what if we designed our code to anticipate and elegantly communicate errors? Please welcome the Result
type, a cornerstone of functional error handling.
At its core, the Result
type encapsulates either a successful value or an error. It might sound similar to exceptions, but there’s a key difference: errors become first-class citizens, directly influencing your application’s flow.
In contrast to the Option
type that can only distinguish existing values from non-existing, the Result
type describes the error that happened and, more importantly, can be used to chain methods application. We will discuss that technique later in this chapter.
For instance, traditionally, a method might return a value or throw an exception:
public Product GetProduct(int id) { var product = _productRepository.Get(id); if(product is null) { &...
Change the font size
Change margin width
Change background colour