liveBook · Manning

Left

As explained in Functional Programming in JavaScript

The left-hand case of an Either value, conventionally used to carry failure or error information.

Left is the error-carrying case of an Either value. It holds failure details while Right holds success, so a computation can return one value and still explain what went wrong. section 5.3

Use Left when a result may fail and you want the failure to travel with the value. This keeps error handling inside the data flow instead of splitting it into separate checks. section 5.3

Left appears in these failure-handling patterns:

  • Wrap a missing lookup result with an error message or exception object. section 5.3

Lookup failure with Left

A safe student lookup returns Either.of(obj) when found, and Left('Object not found with ID: ...') when missing. That lets later code keep chaining without crashing.

Left is tied to Either, Right, error handling, and recovery methods such as getOrElse and orElse. It contrasts with Maybe, which can hide absence but not explain the cause. section 5.3

How Functional Programming in JavaScript covers it

How deep it goes
Defines Left as the error branch and shows its no-op map and recovery methods.
Examples
Uses missing-object lookup and error logging examples.
What it assumes
Assumes basic function chaining and the idea of wrapped values; introduces Either and Left from the ground up.
What you can do after
Operate with error-aware chains that preserve failure details and support fallback handling.
How it connects
Connects to Either, Right, Maybe, getOrElse, and orElse.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.