Created
April 17, 2025 22:42
-
-
Save Xevion/1d13f31a4c1efd1e23a8d724817960e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { fromJson as fromResultJson } from "@/lib/true-myth/result"; | |
import { fromJson as fromMaybeJson } from "@/lib/true-myth/maybe"; | |
export function unreachable(value: never): never { | |
throw new Error(`Should have been unreachable with ${value}`); | |
} | |
export { fromResultJson, fromMaybeJson }; |
This file contains hidden or 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
import { unreachable } from "@/lib/true-myth"; | |
import Maybe, * as maybe from "true-myth/maybe"; | |
export function fromJson<T extends object>(json: maybe.MaybeJSON<T>): Maybe<T> { | |
switch (json.variant) { | |
case "Just": | |
return Maybe.just(json.value); | |
case "Nothing": | |
return Maybe.nothing(); | |
default: | |
unreachable(json); | |
} | |
} |
This file contains hidden or 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
import { unreachable } from "@/lib/true-myth"; | |
import Result, * as result from "true-myth/result"; | |
export function fromJson<T, E>(json: result.ResultJSON<T, E>): Result<T, E> { | |
switch (json.variant) { | |
case "Ok": | |
return Result.ok(json.value); | |
case "Err": | |
return Result.err(json.error); | |
default: | |
unreachable(json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment