import { Task } from "https://deno.land/x/eitherway@0.10.0/lib/async/mod.ts";
Use this to obtain an async iterator of the encapsulated value <T>
In case of failure, this method returns the empty AsyncIteratorResult
Examples
Example 1
Example 1
import { assert } from "../core/assert.ts"
import { Err, Ok, Result, Task } from "https://deno.land/x/eitherway/mod.ts";
const success = Task.succeed(42);
const failure = Task.fail(Error());
async function main() {
const okIter = success.iter();
const errIter = failure.iter();
let okCount = 0;
let okYieldedValue = undefined;
for await (const v of okIter) {
okCount += 1;
okYieldedValue = v;
}
let errCount = 0;
let errYieldedValue = undefined;
for await (const v of errIter) {
errCount += 1;
errYieldedValue = v;
}
assert(okCount === 1);
assert(okYieldedValue === 42);
assert(errCount === 0)
assert(errYieldedValue === undefined);
}
main().then(() => console.log("Done"));