If you have a tree with a node that has a property
P, and all of its parents also need to have property
P is contagious.
When can that happen?
If you wrote in Scala or Haskell before you tried TypeScript, you may have found yourself wondering: Where are the Options at?
For those not familiar, here is an excellent introduction to Scala’s
Option type. At a high level,
Option is an abstraction over
null that gives useful semantics around running functions over possibly-null values. It implements a monad, a functor, and some other structures, but that’s not important for this post.
Flashback to your job interview for your first software engineering job: let’s write a Fibonacci function. We define the base cases of
1, then recurse to generate the rest: