fp-ts Tutorial | Chapter 2.3: Option error handling

preview_player
Показать описание
In Chapter 2.3 of this fp-ts tutorial (functional programming in TypeScript), we will see a concrete example of how to do error handling with Option.

More specifically, we will introduce the Option alt util, which allows us to perform an alternative computation in case the previous computations failed.

00:00 Introduction
01:01 getMovieHighlight implementation
02:28 Option alt definition
02:39 Implementation continued
03:10 Step by step walk-through
06:20 Option altW
Рекомендации по теме
Комментарии
Автор

So you can pipe a series of alts together to perform coalescing, eg. you have multiple possibly None values, and you want the first one that isn't None

ShawnShaddock
Автор

Is possible to obtain the same result by keeping the pipe/flow point free?

squaremarco
Автор

Wonderful, thank you! Shed some light on two concepts I’ve been wanting to learn more about, namely .alt as well as W (Widen).

Is that how I should think when I encounter the W in the various methods? That the return type can be different than the original? Or was that only for this specific context?

dawid_dahl
Автор

[Option] is not really an error. It's an optional value. [Either] is more suitable for error handling. Option just tells you if value exists or not. In real world it would be Either<Option<T>, Error>

CuriousSpy
Автор

Is this approach cleaner that using fold?

rafaelhernandz
visit shbcf.ru