Additional Vocabulary Types
Marc Gregoire · 2024
This chapter starts the discussion with two additional vocabulary types: variant and any. It then continues with a more in-depth discussion of tuples, a generalization of pairs, and their operations. Next is monadic operation support for optionals, which makes chaining operations on optionals so much easier. This is because the readers won't have to verify whether an optional is empty before applying a next operation on it. The chapter finishes with a discussion of expected, which is a data type capable of storing either a value of an expected type or an error value. The type used to represent the error can be different than the type of the value. There are three major options to handle errors in a function. The function can throw an exception; return an error code; or return an expected. They all have their own merits.