.png)
📖 전예홍, ⌈Do it! 타입스크립트 프로그래밍⌋, 이지스퍼블리싱, 2021
👉🏻 데이터의 유무에 따라 코드가 적절하게 동작
class Maybe<T> {
static Just<U>(value: U) {return new Just<U>(value)}
static Nothing = new Nothing
}
👉🏻 데이터가 유효한지 판단
class Validation {
static Success = Success
static Failure = Failure
static of<T>(fn: T): Success<T> {return Success.of<T>(fn)}
}
저번 시간에 이어 Maybe, Validation, IO 모나드를 학습하고 각 클래스를 구현해 보았다. Maybe 모나드는 데이터의 유무를, Validation 모나드는 데이터의 유효성을 판단한다는 차이를 이해했다.