-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { OptionUnion } from "../interfaces"; | ||
export declare function format<T>(option: OptionUnion<T>): string; | ||
import { Option } from "../interfaces"; | ||
export declare function format<T>(option: Option<T>, fn?: (option: Option<T>) => string): string; | ||
//# sourceMappingURL=format.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export function format(option) { | ||
return option.type === "Some" ? `Some(${option.value})` : `None`; | ||
export function format(option, fn) { | ||
const inner = option.inner(); | ||
return inner.type === "Some" | ||
? `Some(${fn?.(option) ?? inner.value})` | ||
: `None`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Option } from "../interfaces"; | ||
export declare function isNoneAnd<T>(option: Option<T>, fn: () => boolean): boolean; | ||
//# sourceMappingURL=isNoneAnd.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isNoneAnd(option, fn) { | ||
return option.isNone() && fn(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { OptionUnion } from "../interfaces"; | ||
export declare function map<T, U>(option: OptionUnion<T>, fn: (value: T) => U): OptionUnion<U>; | ||
import { Option, OptionUnion } from "../interfaces"; | ||
export declare function map<T, U>(option: Option<T>, fn: (value: T) => U): OptionUnion<U>; | ||
//# sourceMappingURL=map.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { OptionUnion } from "../interfaces"; | ||
export declare function unwrap<T>(option: OptionUnion<T>): T; | ||
import { Option } from "../interfaces"; | ||
export declare function unwrap<T>(option: Option<T>): T; | ||
//# sourceMappingURL=unwrap.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { format } from "./format"; | ||
export function unwrap(option) { | ||
if (option.type === "None") { | ||
const inner = option.inner(); | ||
if (inner.type === "None") { | ||
throw new Error(`unwrap called on ${format(option)}`); | ||
} | ||
return option.value; | ||
return inner.value; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { ResultUnion } from "../interfaces"; | ||
export declare function format<T, E>(result: ResultUnion<T, E>): string; | ||
import { Result } from "../interfaces"; | ||
export declare function format<T, E>(result: Result<T, E>, formatter?: (result: Result<T, E>) => string): string; | ||
//# sourceMappingURL=format.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export function format(result) { | ||
return `Result.${result.type}(${result.value})`; | ||
export function format(result, formatter) { | ||
const inner = result.inner(); | ||
return `Result.${inner.type}(${formatter?.(result) ?? inner.value})`; | ||
} |