Skip to content

Commit

Permalink
Remove isErr, isErrAnd, isOk, isOkAnd
Browse files Browse the repository at this point in the history
  • Loading branch information
bkiac committed Nov 4, 2023
1 parent 0bf5190 commit 520097e
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 162 deletions.
17 changes: 0 additions & 17 deletions src/result/err.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Panic, UnwrapPanic} from "../error/panic"
import {inspectSymbol} from "../util"
import type {ErrVariant, Result, ResultMethods} from "./interface"
import type {Ok} from "./ok"

export class ErrImpl<E> implements ErrVariant<E>, ResultMethods<never, E> {
readonly ok = false
Expand Down Expand Up @@ -40,22 +39,6 @@ export class ErrImpl<E> implements ErrVariant<E>, ResultMethods<never, E> {
return this
}

isErr(): this is Err<E> {
return true
}

isErrAnd(f: (error: E) => boolean): this is Err<E> {
return f(this.error)
}

isOk(): this is Ok<never> {
return false
}

isOkAnd(_f: (value: never) => boolean): this is Ok<never> {
return false
}

map<U>(_f: (value: never) => U) {
return this
}
Expand Down
6 changes: 0 additions & 6 deletions src/result/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type {Panic} from "../error/panic"
import type {inspectSymbol} from "../util"
import type {Err} from "./err"
import type {Ok} from "./ok"

export interface ResultMethods<T, E> {
and<U, F>(other: Result<U, F>): Result<U, E | F>
Expand All @@ -10,10 +8,6 @@ export interface ResultMethods<T, E> {
expectErr(panic: string | Panic): E
inspect(f: (value: T) => void): Result<T, E>
inspectErr(f: (error: E) => void): Result<T, E>
isErr(): this is Err<E>
isErrAnd(f: (error: E) => boolean): this is Err<E>
isOk(): this is Ok<T>
isOkAnd(f: (value: T) => boolean): this is Ok<T>
map<U>(f: (value: T) => U): Result<U, E>
mapErr<F>(f: (error: E) => F): Result<T, F>
mapOr<A, B>(defaultValue: A, f: (value: T) => B): A | B
Expand Down
17 changes: 0 additions & 17 deletions src/result/ok.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Panic, UnwrapPanic} from "../error/panic"
import {inspectSymbol} from "../util"
import type {Err} from "./err"
import type {OkVariant, Result, ResultMethods} from "./interface"

export class OkImpl<T> implements OkVariant<T>, ResultMethods<T, never> {
Expand Down Expand Up @@ -40,22 +39,6 @@ export class OkImpl<T> implements OkVariant<T>, ResultMethods<T, never> {
return this
}

isErr(): this is Err<never> {
return false
}

isErrAnd(_f: (error: never) => boolean): this is Err<never> {
return false
}

isOk(): this is Ok<T> {
return true
}

isOkAnd(f: (value: T) => boolean): this is Ok<T> {
return f(this.value)
}

map<U>(f: (value: T) => U) {
return Ok(f(this.value))
}
Expand Down
58 changes: 0 additions & 58 deletions src/result/promise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,64 +137,6 @@ describe.concurrent("inspectErr", async () => {
})
})

describe.concurrent("isErr", () => {
it("returns false for an Ok result", async () => {
const result = new PromiseResult(Promise.resolve(Ok()))
await expect(result.isErr()).resolves.toEqual(false)
})

it("returns true for an Err result", async () => {
const result = new PromiseResult(Promise.resolve(Err(new Error("Test error"))))
await expect(result.isErr()).resolves.toEqual(true)
})
})

describe.concurrent("isErrAnd", () => {
it("returns false for an Ok result", async () => {
const result = new PromiseResult(Promise.resolve(Ok()))
await expect(result.isErrAnd(() => true)).resolves.toEqual(false)
})

it("returns true for an Err result when the provided function returns true", async () => {
const result = new PromiseResult(Promise.resolve(Err(new Error("Test error"))))
await expect(result.isErrAnd(() => true)).resolves.toEqual(true)
})

it("returns false for an Err result when the provided function returns false", async () => {
const result = new PromiseResult(Promise.resolve(Err(new Error("Test error"))))
await expect(result.isErrAnd(() => false)).resolves.toEqual(false)
})
})

describe.concurrent("isOk", () => {
it("returns true for an Ok result", async () => {
const result = new PromiseResult(Promise.resolve(Ok()))
await expect(result.isOk()).resolves.toEqual(true)
})

it("returns false for an Err result", async () => {
const result = new PromiseResult(Promise.resolve(Err(new Error("Test error"))))
await expect(result.isOk()).resolves.toEqual(false)
})
})

describe.concurrent("isOkAnd", () => {
it("returns true for an Ok result when the provided function returns true", async () => {
const result = new PromiseResult(Promise.resolve(Ok()))
await expect(result.isOkAnd(() => true)).resolves.toEqual(true)
})

it("returns false for an Ok result when the provided function returns false", async () => {
const result = new PromiseResult(Promise.resolve(Ok()))
await expect(result.isOkAnd(() => false)).resolves.toEqual(false)
})

it("returns false for an Err result", async () => {
const result = new PromiseResult(Promise.resolve(Err(new Error("Test error"))))
await expect(result.isOkAnd(() => true)).resolves.toEqual(false)
})
})

describe.concurrent("map", () => {
it("returns the mapped value for an Ok result", async () => {
const result = new PromiseResult(Promise.resolve(Ok(42)))
Expand Down
16 changes: 0 additions & 16 deletions src/result/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ export class PromiseResult<T, E> implements PromiseLike<Result<T, E>> {
return new PromiseResult<T, E>(this.then((result) => result.inspectErr(f)))
}

async isErr(): Promise<boolean> {
return (await this).isErr()
}

async isErrAnd(f: (error: E) => boolean): Promise<boolean> {
return (await this).isErrAnd(f)
}

async isOk(): Promise<boolean> {
return (await this).isOk()
}

async isOkAnd(f: (value: T) => boolean): Promise<boolean> {
return (await this).isOkAnd(f)
}

map<U>(f: (value: T) => U): PromiseResult<U, E> {
return new PromiseResult(this.then((result) => result.map(f)))
}
Expand Down
48 changes: 0 additions & 48 deletions src/result/result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,54 +139,6 @@ describe.concurrent("inspectErr", () => {
})
})

describe.concurrent("isErr", () => {
it("returns false for an Ok result", () => {
const result = Ok(42)
expect(result.isErr()).toEqual(false)
})

it("returns true for an Err result", () => {
const result = Err("error")
expect(result.isErr()).toEqual(true)
})
})

describe.concurrent("isErrAnd", () => {
it("returns false for an Ok result", () => {
const result = Ok(42)
expect(result.isErrAnd(() => true)).toEqual(false)
})

it("returns true for an Err result", () => {
const result = Err("error")
expect(result.isErrAnd(() => true)).toEqual(true)
})
})

describe.concurrent("isOk", () => {
it("returns true for an Ok result", () => {
const result = Ok(42)
expect(result.isOk()).toEqual(true)
})

it("returns false for an Err result", () => {
const result = Err("error")
expect(result.isOk()).toEqual(false)
})
})

describe.concurrent("isOkAnd", () => {
it("returns true for an Ok result", () => {
const result = Ok(42)
expect(result.isOkAnd(() => true)).toEqual(true)
})

it("returns false for an Err result", () => {
const result = Err("error")
expect(result.isOkAnd(() => true)).toEqual(false)
})
})

describe.concurrent("map", () => {
it("returns the mapped value for an Ok result", () => {
const result = Ok(42)
Expand Down

0 comments on commit 520097e

Please sign in to comment.