Skip to content

Commit

Permalink
attempt to improve exported API
Browse files Browse the repository at this point in the history
  • Loading branch information
andogq committed Apr 15, 2024
1 parent 8fe3a5a commit e76371e
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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: <T, E>(value: T) => Stream<T, E>;

/**
* Create a stream with a single `error` atom on it.
*/
error: <T, E>(value: E) => Stream<T, E>;

/**
* Create a stream with a single `unknown` atom on it.
*/
unknown: <T, E>(value: unknown) => Stream<T, E>;
};
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,
};

0 comments on commit e76371e

Please sign in to comment.