Reorganization. Split remote/result/request. Split picsum specific api.
This commit is contained in:
parent
5f9bdd5511
commit
c3c629943c
6 changed files with 550 additions and 532 deletions
18
src/result.ts
Normal file
18
src/result.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
export type Result<A, E> = { tag: "ok"; value: A } | { tag: "error"; error: E }
|
||||
|
||||
export const Result = {
|
||||
ok<A>(value: A): Result<A, never> {
|
||||
return { tag: "ok", value }
|
||||
},
|
||||
err<E>(error: E): Result<never, E> {
|
||||
return { tag: "error", error }
|
||||
},
|
||||
map<A, B, E>(result: Result<A, E>, f: (x: A) => B): Result<B, E> {
|
||||
switch (result.tag) {
|
||||
case "ok":
|
||||
return { tag: "ok", value: f(result.value) }
|
||||
case "error":
|
||||
return { tag: "error", error: result.error }
|
||||
}
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue