TaskClass.prototype.ensure<F extends AnyFailure>(): TaskClass<T, E | F>
Declares an invariant on the success value: the value passes through when predicate
holds, otherwise the Task rejects with the declared failure built from the value —
which is what makes it the one-line spelling of the HTTP envelope check:
import { define, is } from '../result/failure.ts'; const PageFailed = define('PageFailed', (d: { status: number }) => `page failed: HTTP ${d.status}`); const respond = (status: number) => Task(() => new Response(null, { status })); const checked = await respond(404).ensure((res) => res.ok, (res) => PageFailed({ status: res.status })).result(); is(checked) && checked.code; // 'PageFailed' — declared, typed, one line await respond(200).ensure((res) => res.ok, (res) => PageFailed({ status: res.status })).map((r) => r.status); // 200