diff --git a/src/index.ts b/src/index.ts index 1ca2f6c..ad2e461 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,41 @@ import { Stream } from "./stream"; import type { StreamBase } from "./stream/base"; -export * as atom from "./atom"; +import { ok, error, unknown, isOk, isError, isUnknown } from "./atom"; export * from "./util"; export { Stream, type StreamEnd } from "./stream"; // Attempt to emulate Highland API -type HighlandConstructor = (typeof StreamBase)["from"] & { of: (typeof StreamBase)["of"] }; +type HighlandConstructor = (typeof StreamBase)["from"] & { + of: (typeof StreamBase)["of"]; + + /** + * Create a stream with a single `ok` atom on it. + */ + ok: (value: T) => 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, +};