-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from clear/feat/api-improvements
create `ofError` and `ofUnknown` methods for creating a stream
- Loading branch information
Showing
8 changed files
with
257 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"windpipe": minor | ||
--- | ||
|
||
create new `ofError` and `ofUnknown` static methods for creating a stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"windpipe": minor | ||
--- | ||
|
||
alter exported API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <T, E>(value: T) => Stream<T, E>; | ||
// Export the `StreamEnd` type | ||
export type { StreamEnd } from "./stream"; | ||
|
||
/** | ||
* 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, | ||
}; | ||
export default Stream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T, E> extends HigherOrderStream<T, E> {} | ||
export class Stream<T, E> extends HigherOrderStream<T, E> { | ||
// Re-export atom utilities for convenience | ||
/** | ||
* Create an `ok` atom with the provided value. | ||
* | ||
* @group Atom | ||
*/ | ||
static ok<T, E>(value: T): Atom<T, E> { | ||
return ok(value); | ||
} | ||
|
||
/** | ||
* Create an `error` atom with the provided value. | ||
* | ||
* @group Atom | ||
*/ | ||
static error<T, E>(value: E): Atom<T, E> { | ||
return error(value); | ||
} | ||
|
||
/** | ||
* Create an `unknown` atom with the provided value. | ||
* | ||
* @group Atom | ||
*/ | ||
static unknown<T, E>(value: unknown, trace: string[]): Atom<T, E> { | ||
return unknown(value, trace); | ||
} | ||
|
||
/** | ||
* Verify if the provided atom is of the `ok` variant. | ||
* | ||
* @group Atom | ||
*/ | ||
static isOk<T, E>(atom: Atom<T, E>): atom is AtomOk<T> { | ||
return isOk(atom); | ||
} | ||
|
||
/** | ||
* Verify if the provided atom is of the `error` variant. | ||
* | ||
* @group Atom | ||
*/ | ||
static isError<T, E>(atom: Atom<T, E>): atom is AtomError<E> { | ||
return isError(atom); | ||
} | ||
|
||
/** | ||
* Verify if the provided atom is of the `unknown` variant. | ||
* | ||
* @group Atom | ||
*/ | ||
static isUnknown<T, E>(atom: Atom<T, E>): atom is AtomUnknown { | ||
return isUnknown(atom); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.