Skip to content

This is just a simple `Unit` of change

Compare
Choose a tag to compare
@chriskrycho chriskrycho released this 02 Nov 21:24
· 1373 commits to main since this release

What's new?

  • Adds a Unit type (which is basically just a simple object with a private field), so you can have a type to use with e.g. Result instead of re-infecting your system with void.
  • Supports nice construction of Result<Unit, E> or Result<T, Unit> with Result.ok() and Result.err() invocations respectively (don't worry: it still throws if you pass null to either of those, or if you pass either undefined or null or nothing at all to the Result.Ok or Result.Err constructors).
import Result, { ok, err } from 'true-myth/result';
import Unit from 'true-myth/unit';

const getAResultWithUnit = (isValid: boolean): Result<Unit, string> =>
  isValid ? Result.ok() : Result.err("this wasn't valid");