Result
Result is the small tagged union used by the build APIs and accepted by dependency constructors.
import { Result } from '@fuiste/dependencies'
Constructors
const success = Result.ok(42)
const failure = Result.err('nope')
Guards
if (Result.isOk(result)) {
result.value
}
if (Result.isErr(result)) {
result.error
}
Result.isResult(value) checks whether an unknown value has an ok or err tag.
Mapping
const next = Result.map(result, (value) => value + 1)
const normalized = Result.mapError(result, (error) => String(error))
Matching
const message = Result.match(result, {
ok: (value) => `value: ${value}`,
err: (error) => `error: ${error}`,
})
There is no secret monad transformer stack hiding behind the couch. It is just a tagged union with a few helpers.