-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
1,682 additions
and
1,596 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Err, Ok } from "./result.ts"; | ||
import { Effect, Operation } from "./types.ts"; | ||
|
||
interface Resolver<T> { | ||
(resolve: (value: T) => void, reject: (error: Error) => void): () => void; | ||
} | ||
|
||
export function action<T>(resolver: Resolver<T>, desc?: string): Operation<T> { | ||
return { | ||
*[Symbol.iterator]() { | ||
let action: Effect<T> = { | ||
description: desc ?? "action", | ||
enter: (settle) => { | ||
let resolve = (value: T) => { | ||
settle(Ok(value)); | ||
}; | ||
let reject = (error: Error) => { | ||
settle(Err(error)); | ||
}; | ||
let discard = resolver(resolve, reject); | ||
return (discarded) => { | ||
try { | ||
discard(); | ||
discarded(Ok()); | ||
} catch (error) { | ||
discarded(Err(error)); | ||
} | ||
}; | ||
}, | ||
}; | ||
return (yield action) as T; | ||
}, | ||
}; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { lift } from "./lift.ts"; | ||
import { Err, Ok, Result, unbox } from "./result.ts"; | ||
import { Operation } from "./types.ts"; | ||
import { withResolvers } from "./with-resolvers.ts"; | ||
import { spawn } from "./spawn.ts"; | ||
import { encapsulate } from "./task.ts"; | ||
|
||
export function* callcc<T>( | ||
op: ( | ||
resolve: (value: T) => Operation<void>, | ||
reject: (error: Error) => Operation<void>, | ||
) => Operation<void>, | ||
): Operation<T> { | ||
let result = withResolvers<Result<T>>(); | ||
|
||
let resolve = lift((value: T) => result.resolve(Ok(value))); | ||
|
||
let reject = lift((error: Error) => result.resolve(Err(error))); | ||
|
||
return yield* encapsulate(function* () { | ||
yield* spawn(() => op(resolve, reject)); | ||
|
||
return unbox(yield* result.operation); | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Operation } from "./types.ts"; | ||
|
||
export function constant<T>(value: T): Operation<T> { | ||
return { | ||
[Symbol.iterator]: () => ({ next: () => ({ done: true, value }) }), | ||
}; | ||
} |
Oops, something went wrong.