Robin Pokorny
1 min readAug 16, 2021

--

Hey Jason,

Thanks for elaborating on that.

First, I agree that ternary is superior to if/else and I do not want to get dragged to the TS rant 😅

But those are rather details, I think.

The main point is that sometimes you cannot represent a missing value with `null` or `undefined`, because the non-missing value may be `null` or `undefined`.

Now, there is a pattern on how to deal with it called Option/Maybe (monad). You can see one of many implementations here https://gcanti.github.io/fp-ts/modules/Option.ts.html (warning: a lot of <>'s and single-letter variables)

In my article, I show a lightweight (IMHO) implementation of basically the same using Symbols.

Then the examples are more showing how it compares to other Option implementations. I agree it's not clear, that you do not need (or even should use) these abstract functions and you would implement the `None` check yourself inside your business logic.

I personally see value in having the domain reason included in the missing value, which I think improves readability and could be handy in debugging.

--

--

Robin Pokorny
Robin Pokorny

Written by Robin Pokorny

Architecture & Tech Leadership — Speaks — Loves maths — Reads specs — Podcasts — Lives in Berlin — robinpokorny.com

Responses (1)