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 throw
s 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");