Search⌘ K
AI Features

Before We Continue: Either or Validation?

Explore the differences between Either and Validation in fp-ts when handling user input validations. Understand how Validation aggregates errors for better feedback and when Either is preferable for simpler or exclusive failure scenarios, helping you build robust user registration processes.

We'll cover the following...

Either vs. Validation

Suppose we receive data from a frontend where a user has just filled in their information. A situation where the user fixes their errors one at a time instead of just getting back a list of all problems might not be ideal. This might lead to user frustration and additional calls to our backend because the data is resubmitted multiple times. This is why Validation can be a useful alternative to Either.

To demonstrate its potential, we’ll rewrite our three checks… The first thing we’ll need is a semigroup for an array of strings. We’ll pass it to the getValidation helper from ...

TypeScript 3.3.4
import * as E from 'fp-ts/lib/Either';
import {getSemigroup} from 'fp-ts/lib/NonEmptyArray'
const applicativeValidation = E.getValidation(getSemigroup<string>());

A ...