Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

egghead.io

Safer JavaScript with the Maybe Type

via egghead.io

Overview

JavaScript’s dynamic typing makes it incredibly flexible. That flexibility can lead to trouble though. When values have the potential to change types or to end up as null or undefined, that can lead to runtime errors in our code or bizarre bugs that take forever to track down because of type coercion. To battle this, we end up with code that is littered will conditionals for null or undefined values and type checks, making the core logic harder to read and refactor later.
The Maybe encapsulates the type checking and guards against missing values for us. With Maybe in our toolbelt, we can keep our functions free of all the guardrails, outsource that work to the Maybe and keep our business logic free of all the clutter.

Syllabus

  • Course Introduction: Safer JavaScript with the Maybe type
  • Understand the Maybe Data Type
  • Create a Maybe with a `safe` Utility Function
  • Unwrap Values from a Maybe
  • Safely Access Object Properties with `prop`
  • Safely Access Nested Object Properties with `propPath`
  • Flatten Nested Maybes with `chain`
  • Recover from a Nothing with the `alt` method
  • Recover from a Nothing with the `coalesce` Method
  • Compose Functions for Reusability with the Maybe Type
  • Apply a function in a Maybe context to Maybe inputs
  • Make your own functions safer by lifting them into a Maybe context

Taught by

Andy Van Slaars

Reviews

4.4 rating at egghead.io based on 236 ratings

Start your review of Safer JavaScript with the Maybe Type

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.