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
import { | |
all, | |
createChannel, | |
type Operation, | |
resource, | |
spawn, | |
type Stream, | |
} from "effection"; | |
export function zip<T>(streams: Stream<T, never>[]): Stream<T[], never> { |
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
import { createChannel, resource, all, spawn, main, type Stream } from "effection"; | |
type bit = 0 | 1; | |
type Bit = Stream<bit, never>; | |
function create1BitAdder(a$: Bit, b$: Bit, c$: Bit): Stream<[bit, bit], never> { | |
// the easiest way to represent a stream is as a resource because | |
// a resource that "provides" a subscription is by definition a stream | |
// because a stream is an operation that yields a subscription | |
return resource(function*(provide) { |
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
import type { Resolve, Subscription } from "./types.ts"; | |
import { action } from "./instructions.ts"; | |
export interface Queue<T, TClose> extends Subscription<T, TClose> { | |
add(item: T): void; | |
close(value: TClose): void; | |
} | |
export function createQueue<T, TClose>(): Queue<T, TClose> { | |
type Item = IteratorResult<T, TClose>; |
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
/** | |
* Takes a buffer limit, and returns a stream combinator that converts a stream into stream | |
* limits the number of in flight items to that limit when it is subscribed to. Use with pipe: | |
* ```ts | |
* let doubleclicks = pipe(events, buffer(200), filter(isDoubleClick)); | |
* ``` | |
* Or as a standalone: | |
* let buffered = buffer(200)(events); | |
* | |
* No buffer is actually allocated until the resulting stream is subscribed to. |
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
import { filter } from "effection"; | |
export function* useActions(pattern: ActionPattern): Stream<AnyAction> { | |
let match = matcher(pattern); | |
let { output } = yield* ActionContext; | |
// return a subscription to the filtered actions. | |
return yield* filter(match)(output); | |
} |
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
import { createChannel, run, type Stream } from "./mod.ts"; | |
export function createSignal<T>(): [(event: T) => void, Stream<T, never>] { | |
let { input, output } = createChannel<T, never>(); | |
let pulse = (event: T) => run(() => input.send(event)); | |
return [pulse, output]; | |
} |
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
import { | |
action, | |
createChannel, | |
createContext, | |
exit, | |
expect, | |
main, | |
type Operation, | |
spawn, | |
Stream, |
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
export default function*() { | |
return "Hello World!"; | |
} |
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
import { setup, virtual, tw, stringify } from "https://esm.sh/@twind/core@1.1.3"; | |
const sheet = virtual(); | |
setup({}, sheet); | |
const classnames = tw("grid grid-cols-2"); | |
console.dir({ | |
"sheet.target === tw.target": sheet.target === tw.target, |
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
import type { Operation, Provide, Resolve, Reject, Result } from "./deps.ts"; | |
export type ActionFn = (resolve: Resolve, reject: Reject) => Operation<void>; | |
export type Instruction = | |
| { | |
name: "spawn"; | |
operation(): Operation<unknown>; | |
} | |
| { |