Skip to content

Commit

Permalink
feat: Callsites accepting Results or Options should be monomorphic
Browse files Browse the repository at this point in the history
  • Loading branch information
Olian04 committed Feb 22, 2024
1 parent db33a5a commit 8cacbae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Some<V> {
export interface None {
readonly isSome: false;
readonly isNone: true;
readonly some: never;
match<T>(cases: {
None: () => T,
}): T;
Expand Down Expand Up @@ -80,6 +81,7 @@ export const Some = <V>(value: V): Some<V> => new SomeImpl(value);
export const None: None = {
isSome: false as const,
isNone: true as const,
some: undefined as never,
match: cases => cases.None(),
intoResult: err => new ErrImpl(err),
filter: () => None,
Expand Down
4 changes: 4 additions & 0 deletions src/Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Ok<V> {
readonly isOk: true;
readonly isErr: false;
readonly ok: V;
readonly err: never;
match<T>(cases: {
Ok: (ok: V) => T,
}): T;
Expand All @@ -25,6 +26,7 @@ export interface Ok<V> {
export interface Err<E> {
readonly isOk: false;
readonly isErr: true;
readonly ok: never;
readonly err: E;
match<T>(cases: {
Err: (err: E) => T,
Expand All @@ -43,6 +45,7 @@ export interface Err<E> {
export class OkImpl<V> implements Ok<V> {
isOk = true as const;
isErr = false as const;
err: never;
constructor(
public ok: V,
) {}
Expand Down Expand Up @@ -82,6 +85,7 @@ export class OkImpl<V> implements Ok<V> {
export class ErrImpl<E> implements Err<E> {
isOk = false as const;
isErr = true as const;
ok: never;
constructor(
public err: E,
) {}
Expand Down

0 comments on commit 8cacbae

Please sign in to comment.