diff --git a/.changeset/silent-pandas-talk.md b/.changeset/silent-pandas-talk.md new file mode 100644 index 0000000..c779b5c --- /dev/null +++ b/.changeset/silent-pandas-talk.md @@ -0,0 +1,5 @@ +--- +"windpipe": minor +--- + +create new `ofError` and `ofUnknown` static methods for creating a stream diff --git a/.changeset/three-forks-learn.md b/.changeset/three-forks-learn.md new file mode 100644 index 0000000..3c13601 --- /dev/null +++ b/.changeset/three-forks-learn.md @@ -0,0 +1,5 @@ +--- +"windpipe": minor +--- + +alter exported API diff --git a/package.json b/package.json index 1b9db67..77a1140 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "lint": "tsc && eslint .", "format": "eslint --fix .", - "build": "tsup ./src/index.ts --format esm,cjs --dts", + "build": "tsup ./src/index.ts --format esm,cjs --dts --splitting --cjsInterop", "doc": "typedoc ./src --media ./media --plugin typedoc-plugin-extras --favicon ./media/favicon.ico --footerLastModified true --plugin typedoc-material-theme --themeColor '#03284e'", "test": "vitest", "ci:release": "npm run build && changeset publish" diff --git a/src/index.ts b/src/index.ts index 8528975..7ebbff5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,42 +1,12 @@ import { Stream } from "./stream"; -import type { StreamBase } from "./stream/base"; -import { ok, error, unknown, isOk, isError, isUnknown } from "./atom"; -export * from "./util"; -export { Stream, type StreamEnd } from "./stream"; +// Export all useful types for atoms export type { Atom, AtomOk, AtomError, AtomUnknown } from "./atom"; -// Attempt to emulate Highland API -type HighlandConstructor = (typeof StreamBase)["from"] & { - of: (typeof StreamBase)["of"]; +// Re-export all utility types +export type * from "./util"; - /** - * Create a stream with a single `ok` atom on it. - */ - ok: (value: T) => Stream; +// Export the `StreamEnd` type +export type { StreamEnd } from "./stream"; - /** - * Create a stream with a single `error` atom on it. - */ - error: (value: E) => Stream; - - /** - * Create a stream with a single `unknown` atom on it. - */ - unknown: (value: unknown) => Stream; -}; -export const $: HighlandConstructor = Stream.from as HighlandConstructor; -$.of = Stream.of; - -$.ok = (value) => Stream.of(ok(value)); -$.error = (value) => Stream.of(error(value)); -$.unknown = (value) => Stream.of(unknown(value, [])); - -export const atom = { - ok, - error, - unknown, - isOk, - isError, - isUnknown, -}; +export default Stream; diff --git a/src/stream/base.ts b/src/stream/base.ts index 018ff77..7fd3293 100644 --- a/src/stream/base.ts +++ b/src/stream/base.ts @@ -1,4 +1,4 @@ -import { normalise, type Atom, type MaybeAtom } from "../atom"; +import { normalise, type Atom, type MaybeAtom, error, unknown } from "../atom"; import { Stream } from "."; import { Readable, Writable } from "stream"; @@ -184,6 +184,12 @@ export class StreamBase { ); } + /** + * Create a new stream containing a single value. Unless an atom is provided, it will be + * converted to an `ok` atom. + * + * @group Creation + */ static of(value: MaybeAtom): Stream { let consumed = false; return Stream.fromNext(async () => { @@ -196,6 +202,24 @@ export class StreamBase { }); } + /** + * Create a new stream containing a single error atom. + * + * @group Creation + */ + static ofError(value: E): Stream { + return this.of(error(value)); + } + + /** + * Create a new stream containing a single unknown atom. + * + * @group Creation + */ + static ofUnknown(value: unknown): Stream { + return this.of(unknown(value, [])); + } + /** * Create a stream and corresponding writable Node stream, where any writes to the writable * Node stream will be emitted on the returned stream. diff --git a/src/stream/index.ts b/src/stream/index.ts index 442420d..71b93b8 100644 --- a/src/stream/index.ts +++ b/src/stream/index.ts @@ -1,5 +1,72 @@ +import { + ok, + error, + unknown, + isOk, + isError, + isUnknown, + type Atom, + type AtomOk, + type AtomError, + type AtomUnknown, +} from "../atom"; import { HigherOrderStream } from "./higher-order"; export type { StreamEnd } from "./base"; -export class Stream extends HigherOrderStream {} +export class Stream extends HigherOrderStream { + // Re-export atom utilities for convenience + /** + * Create an `ok` atom with the provided value. + * + * @group Atom + */ + static ok(value: T): Atom { + return ok(value); + } + + /** + * Create an `error` atom with the provided value. + * + * @group Atom + */ + static error(value: E): Atom { + return error(value); + } + + /** + * Create an `unknown` atom with the provided value. + * + * @group Atom + */ + static unknown(value: unknown, trace: string[]): Atom { + return unknown(value, trace); + } + + /** + * Verify if the provided atom is of the `ok` variant. + * + * @group Atom + */ + static isOk(atom: Atom): atom is AtomOk { + return isOk(atom); + } + + /** + * Verify if the provided atom is of the `error` variant. + * + * @group Atom + */ + static isError(atom: Atom): atom is AtomError { + return isError(atom); + } + + /** + * Verify if the provided atom is of the `unknown` variant. + * + * @group Atom + */ + static isUnknown(atom: Atom): atom is AtomUnknown { + return isUnknown(atom); + } +} diff --git a/src/util.ts b/src/util.ts index 545a735..44ea9d3 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,4 @@ -import type { Stream } from "."; +import Stream from "."; /** * Maybe it's a promise. Maybe it's not. Who's to say. diff --git a/test/index.test.ts b/test/index.test.ts index 48762a0..5a29708 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,6 +1,5 @@ import { describe, test, vi } from "vitest"; -import { Stream } from "../src"; -import { ok, error, unknown } from "../src/atom"; +import $ from "../src"; import { Readable } from "stream"; describe.concurrent("stream creation", () => { @@ -8,9 +7,9 @@ describe.concurrent("stream creation", () => { test("resolving promise to emit value", async ({ expect }) => { expect.assertions(1); - const s = Stream.fromPromise(Promise.resolve(10)); + const s = $.fromPromise(Promise.resolve(10)); - expect(await s.toArray({ atoms: true })).toEqual([ok(10)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(10)]); }); }); @@ -18,7 +17,7 @@ describe.concurrent("stream creation", () => { test("multi-value generator", async ({ expect }) => { expect.assertions(1); - const s = Stream.fromIterator( + const s = $.fromIterator( (function* () { yield 1; yield 2; @@ -26,13 +25,13 @@ describe.concurrent("stream creation", () => { })(), ); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2), $.ok(3)]); }); test("multi-value async generator", async ({ expect }) => { expect.assertions(1); - const s = Stream.fromIterator( + const s = $.fromIterator( (async function* () { yield 1; yield 2; @@ -40,7 +39,7 @@ describe.concurrent("stream creation", () => { })(), ); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2), $.ok(3)]); }); }); @@ -48,17 +47,17 @@ describe.concurrent("stream creation", () => { test("array iterable", async ({ expect }) => { expect.assertions(1); - const s = Stream.fromIterable([1, 2, 3]); + const s = $.fromIterable([1, 2, 3]); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2), $.ok(3)]); }); test("readable stream", async ({ expect }) => { expect.assertions(1); - const s = Stream.fromIterable(Readable.from([1, 2, 3])); + const s = $.fromIterable(Readable.from([1, 2, 3])); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2), $.ok(3)]); }); }); }); @@ -68,45 +67,53 @@ describe.concurrent("stream transforms", () => { test("synchronous value", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3]).map((n) => n * 10); + const s = $.from([1, 2, 3]).map((n) => n * 10); - expect(await s.toArray({ atoms: true })).toEqual([ok(10), ok(20), ok(30)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(10), $.ok(20), $.ok(30)]); }); test("synchronous atom", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3]).map((n) => { + const s = $.from([1, 2, 3]).map((n) => { if (n === 2) { - return error("number 2"); + return $.error("number 2"); } else { - return ok(n); + return $.ok(n); } }); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), error("number 2"), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([ + $.ok(1), + $.error("number 2"), + $.ok(3), + ]); }); test("synchronous mix", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3]).map((n) => { + const s = $.from([1, 2, 3]).map((n) => { if (n === 2) { - return error("number 2"); + return $.error("number 2"); } else { return n; } }); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), error("number 2"), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([ + $.ok(1), + $.error("number 2"), + $.ok(3), + ]); }); test("asynchronous value", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3]).map(async (n) => n * 10); + const s = $.from([1, 2, 3]).map(async (n) => n * 10); - expect(await s.toArray({ atoms: true })).toEqual([ok(10), ok(20), ok(30)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(10), $.ok(20), $.ok(30)]); }); }); @@ -114,17 +121,21 @@ describe.concurrent("stream transforms", () => { test("single error", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([error(1), ok(2), ok(3)]).mapError((_e) => ok("error")); + const s = $.from([$.error(1), $.ok(2), $.ok(3)]).mapError((_e) => $.ok("error")); - expect(await s.toArray({ atoms: true })).toEqual([ok("error"), ok(2), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok("error"), $.ok(2), $.ok(3)]); }); test("multiple errors", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([error(1), ok(2), error(3)]).mapError((e) => ok("error" + e)); + const s = $.from([$.error(1), $.ok(2), $.error(3)]).mapError((e) => $.ok("error" + e)); - expect(await s.toArray({ atoms: true })).toEqual([ok("error1"), ok(2), ok("error3")]); + expect(await s.toArray({ atoms: true })).toEqual([ + $.ok("error1"), + $.ok(2), + $.ok("error3"), + ]); }); }); @@ -132,19 +143,19 @@ describe.concurrent("stream transforms", () => { test("single unknown", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([unknown(1, []), ok(2), ok(3)]).mapUnknown((e) => error(e)); + const s = $.from([$.unknown(1, []), $.ok(2), $.ok(3)]).mapUnknown((e) => $.error(e)); - expect(await s.toArray({ atoms: true })).toEqual([error(1), ok(2), ok(3)]); + expect(await s.toArray({ atoms: true })).toEqual([$.error(1), $.ok(2), $.ok(3)]); }); test("multiple unknown", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([unknown(1, []), ok(2), unknown(3, [])]).mapUnknown((e) => - error(e), + const s = $.from([$.unknown(1, []), $.ok(2), $.unknown(3, [])]).mapUnknown((e) => + $.error(e), ); - expect(await s.toArray({ atoms: true })).toEqual([error(1), ok(2), error(3)]); + expect(await s.toArray({ atoms: true })).toEqual([$.error(1), $.ok(2), $.error(3)]); }); }); @@ -152,19 +163,23 @@ describe.concurrent("stream transforms", () => { test("synchronous values", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3, 4]).filter((n) => n % 2 === 0); + const s = $.from([1, 2, 3, 4]).filter((n) => n % 2 === 0); - expect(await s.toArray({ atoms: true })).toEqual([ok(2), ok(4)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(2), $.ok(4)]); }); test("synchronous atoms", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, error("an error"), 2, 3, 4]) + const s = $.from([1, $.error("an error"), 2, 3, 4]) // Perform the actual filter operation .filter((n) => n % 2 === 0); - expect(await s.toArray({ atoms: true })).toEqual([error("an error"), ok(2), ok(4)]); + expect(await s.toArray({ atoms: true })).toEqual([ + $.error("an error"), + $.ok(2), + $.ok(4), + ]); }); }); @@ -172,33 +187,33 @@ describe.concurrent("stream transforms", () => { test("multiple values", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3, 4, 5]).drop(2); + const s = $.from([1, 2, 3, 4, 5]).drop(2); - expect(await s.toArray({ atoms: true })).toEqual([ok(3), ok(4), ok(5)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(3), $.ok(4), $.ok(5)]); }); test("multiple values with errors", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, error("some error"), 2, 3, 4, 5]).drop(2); + const s = $.from([1, $.error("some error"), 2, 3, 4, 5]).drop(2); - expect(await s.toArray({ atoms: true })).toEqual([ok(3), ok(4), ok(5)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(3), $.ok(4), $.ok(5)]); }); test("multiple atoms", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3, 4, 5]).drop(2, { atoms: true }); + const s = $.from([1, 2, 3, 4, 5]).drop(2, { atoms: true }); - expect(await s.toArray({ atoms: true })).toEqual([ok(3), ok(4), ok(5)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(3), $.ok(4), $.ok(5)]); }); test("multiple atoms with errors", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, error("some error"), 2, 3, 4, 5]).drop(2, { atoms: true }); + const s = $.from([1, $.error("some error"), 2, 3, 4, 5]).drop(2, { atoms: true }); - expect(await s.toArray({ atoms: true })).toEqual([ok(2), ok(3), ok(4), ok(5)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(2), $.ok(3), $.ok(4), $.ok(5)]); }); }); }); @@ -207,7 +222,7 @@ describe.concurrent("error handling", () => { test("throw in map", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3]).map((n) => { + const s = $.from([1, 2, 3]).map((n) => { if (n === 2) { // Unhandled error throw new Error("bad number"); @@ -217,9 +232,9 @@ describe.concurrent("error handling", () => { }); expect(await s.toArray({ atoms: true })).toEqual([ - ok(1), - unknown(new Error("bad number"), ["map"]), - ok(3), + $.ok(1), + $.unknown(new Error("bad number"), ["map"]), + $.ok(3), ]); }); @@ -234,19 +249,19 @@ describe.concurrent("error handling", () => { } } - const s = Stream.from([1, 2, 3]).map(process); + const s = $.from([1, 2, 3]).map(process); expect(await s.toArray({ atoms: true })).toEqual([ - ok(1), - unknown(new Error("bad number"), ["map"]), - ok(3), + $.ok(1), + $.unknown(new Error("bad number"), ["map"]), + $.ok(3), ]); }); test("track multiple transforms", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3, 4, 5]) + const s = $.from([1, 2, 3, 4, 5]) .map((n) => { if (n === 2) { // Unhandled error @@ -258,15 +273,15 @@ describe.concurrent("error handling", () => { .filter((n) => n % 2 === 0); expect(await s.toArray({ atoms: true })).toEqual([ - unknown(new Error("bad number"), ["map"]), - ok(4), + $.unknown(new Error("bad number"), ["map"]), + $.ok(4), ]); }); test("error thrown in later transform", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3, 4, 5]) + const s = $.from([1, 2, 3, 4, 5]) .filter((n) => n > 1) .map((n) => { if (n % 2 === 1) { @@ -286,10 +301,10 @@ describe.concurrent("error handling", () => { .filter((n) => n % 2 === 0); expect(await s.toArray({ atoms: true })).toEqual([ - unknown(new Error("bad number"), ["filter", "map", "map"]), - ok(30), - ok(4), - ok(50), + $.unknown(new Error("bad number"), ["filter", "map", "map"]), + $.ok(30), + $.ok(4), + $.ok(50), ]); }); }); @@ -299,58 +314,58 @@ describe.concurrent("higher order streams", () => { test("returning stream", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3]).flatMap((n) => Stream.from(new Array(n).fill(n))); + const s = $.from([1, 2, 3]).flatMap((n) => $.from(new Array(n).fill(n))); expect(await s.toArray({ atoms: true })).toEqual([ - ok(1), - ok(2), - ok(2), - ok(3), - ok(3), - ok(3), + $.ok(1), + $.ok(2), + $.ok(2), + $.ok(3), + $.ok(3), + $.ok(3), ]); }); test("returning stream or error", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1, 2, 3]).flatMap((n) => { + const s = $.from([1, 2, 3]).flatMap((n) => { if (n === 2) { - return error("number two"); + return $.error("number two"); } - return Stream.from(new Array(n).fill(n)); + return $.from(new Array(n).fill(n)); }); expect(await s.toArray({ atoms: true })).toEqual([ - ok(1), - error("number two"), - ok(3), - ok(3), - ok(3), + $.ok(1), + $.error("number two"), + $.ok(3), + $.ok(3), + $.ok(3), ]); }); test("errors already in stream", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([ - ok(1), - error("known error"), - ok(2), - unknown("bad error", []), - ok(3), - ]).flatMap((n) => Stream.from(new Array(n).fill(n))); + const s = $.from([ + $.ok(1), + $.error("known error"), + $.ok(2), + $.unknown("bad error", []), + $.ok(3), + ]).flatMap((n) => $.from(new Array(n).fill(n))); expect(await s.toArray({ atoms: true })).toEqual([ - ok(1), - error("known error"), - ok(2), - ok(2), - unknown("bad error", []), - ok(3), - ok(3), - ok(3), + $.ok(1), + $.error("known error"), + $.ok(2), + $.ok(2), + $.unknown("bad error", []), + $.ok(3), + $.ok(3), + $.ok(3), ]); }); }); @@ -360,11 +375,11 @@ describe.concurrent("higher order streams", () => { expect.assertions(3); const subCallback = vi.fn(); - const callback = vi.fn().mockImplementation((n) => Stream.of(n * n).tap(subCallback)); - const s = Stream.from([1, 2, 3, 4]).flatTap(callback); + const callback = vi.fn().mockImplementation((n) => $.of(n * n).tap(subCallback)); + const s = $.from([1, 2, 3, 4]).flatTap(callback); // Ensure that the flat tap doesn't alter the emitted stream items - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2), ok(3), ok(4)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2), $.ok(3), $.ok(4)]); // Ensure that the flatTap implementation is called once for each item in the stream expect(callback).toBeCalledTimes(4); @@ -376,10 +391,10 @@ describe.concurrent("higher order streams", () => { test("simple stream", async ({ expect }) => { expect.assertions(2); - const callback = vi.fn().mockImplementation((n) => Stream.of(n * n)); - const s = Stream.from([1, 2, 3, 4]).flatTap(callback); + const callback = vi.fn().mockImplementation((n) => $.of(n * n)); + const s = $.from([1, 2, 3, 4]).flatTap(callback); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2), ok(3), ok(4)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2), $.ok(3), $.ok(4)]); expect(callback).toBeCalledTimes(4); }); }); @@ -388,55 +403,55 @@ describe.concurrent("higher order streams", () => { test("empty stream", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([]).otherwise(Stream.from([1, 2])); + const s = $.from([]).otherwise($.from([1, 2])); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2)]); }); test("non-empty stream", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([1]).otherwise(Stream.from([2, 3])); + const s = $.from([1]).otherwise($.from([2, 3])); - expect(await s.toArray({ atoms: true })).toEqual([ok(1)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1)]); }); test("empty stream with otherwise function", async ({ expect }) => { expect.assertions(2); - const otherwise = vi.fn().mockReturnValue(Stream.from([1, 2])); + const otherwise = vi.fn().mockReturnValue($.from([1, 2])); - const s = Stream.from([]).otherwise(otherwise); + const s = $.from([]).otherwise(otherwise); - expect(await s.toArray({ atoms: true })).toEqual([ok(1), ok(2)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1), $.ok(2)]); expect(otherwise).toHaveBeenCalledOnce(); }); test("non-empty stream with otherwise function", async ({ expect }) => { expect.assertions(2); - const otherwise = vi.fn().mockReturnValue(Stream.from([2, 3])); + const otherwise = vi.fn().mockReturnValue($.from([2, 3])); - const s = Stream.from([1]).otherwise(otherwise); + const s = $.from([1]).otherwise(otherwise); - expect(await s.toArray({ atoms: true })).toEqual([ok(1)]); + expect(await s.toArray({ atoms: true })).toEqual([$.ok(1)]); expect(otherwise).not.toHaveBeenCalled(); }); test("stream with known error", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([error("some error")]).otherwise(Stream.from([1])); + const s = $.from([$.error("some error")]).otherwise($.from([1])); - expect(await s.toArray({ atoms: true })).toEqual([error("some error")]); + expect(await s.toArray({ atoms: true })).toEqual([$.error("some error")]); }); test("stream with unknown error", async ({ expect }) => { expect.assertions(1); - const s = Stream.from([unknown("some error", [])]).otherwise(Stream.from([1])); + const s = $.from([$.unknown("some error", [])]).otherwise($.from([1])); - expect(await s.toArray({ atoms: true })).toEqual([unknown("some error", [])]); + expect(await s.toArray({ atoms: true })).toEqual([$.unknown("some error", [])]); }); }); }); @@ -446,7 +461,7 @@ describe.concurrent("stream consumption", () => { test("values", async ({ expect }) => { expect.assertions(1); - const array = await Stream.from([1, 2, 3]).toArray(); + const array = await $.from([1, 2, 3]).toArray(); expect(array).toEqual([1, 2, 3]); }); @@ -454,12 +469,12 @@ describe.concurrent("stream consumption", () => { test("values with errors on stream", async ({ expect }) => { expect.assertions(1); - const array = await Stream.from([ + const array = await $.from([ 1, - error("known"), + $.error("known"), 2, 3, - unknown("error", []), + $.unknown("$.error", []), ]).toArray(); expect(array).toEqual([1, 2, 3]); @@ -468,7 +483,7 @@ describe.concurrent("stream consumption", () => { test("values with no items on stream", async ({ expect }) => { expect.assertions(1); - const array = await Stream.from([]).toArray(); + const array = await $.from([]).toArray(); expect(array).toEqual([]); }); @@ -476,29 +491,37 @@ describe.concurrent("stream consumption", () => { test("atoms", async ({ expect }) => { expect.assertions(1); - const array = await Stream.from([1, 2, 3]).toArray({ atoms: true }); + const array = await $.from([1, 2, 3]).toArray({ atoms: true }); - expect(array).toEqual([ok(1), ok(2), ok(3)]); + expect(array).toEqual([$.ok(1), $.ok(2), $.ok(3)]); }); test("atoms with errors on stream", async ({ expect }) => { expect.assertions(1); - const array = await Stream.from([ + const array = await $.from([ 1, - error("known"), + $.error("known"), 2, 3, - unknown("error", []), - ]).toArray({ atoms: true }); + $.unknown("$.error", []), + ]).toArray({ + atoms: true, + }); - expect(array).toEqual([ok(1), error("known"), ok(2), ok(3), unknown("error", [])]); + expect(array).toEqual([ + $.ok(1), + $.error("known"), + $.ok(2), + $.ok(3), + $.unknown("$.error", []), + ]); }); test("atoms with no items on stream", async ({ expect }) => { expect.assertions(1); - const array = await Stream.from([]).toArray({ atoms: true }); + const array = await $.from([]).toArray({ atoms: true }); expect(array).toEqual([]); });