Last active
April 19, 2023 17:38
-
-
Save cowboyd/384b456e7093462ac0b1c7b33d6213d7 to your computer and use it in GitHub Desktop.
Piping, buffering, filtering, mapping, and general hypothetical combinations API.
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 { buffer, on, flow, filter } from "effection"; | |
let results = flow( | |
on('message'), | |
buffer({ size: 100 }), | |
map(message => JSON.parse(message.data)), | |
filter(data => data.type === "result"), | |
); | |
let websocket = new WebSocket('wss://localhost:9000'); | |
// in this example, forEach is not a combinator, just a regular function | |
yield* forEach(results(websocket), function*(result) { | |
console.log('received result from websocket', result) | |
}); |
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 { buffer, on, pipe, filter } from "effection"; | |
yield* pipe( | |
new WebSocket('wss://localhost:9000'), | |
on('message'), | |
buffer({ size: 100 }), | |
map(message => JSON.parse(message.data)), | |
filter(data => data.type === "result"), | |
forEach(function*() { | |
console.log('received result from websocket', result) | |
}) | |
); |
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 { buffer, on, flow, filter } from "effection"; | |
let results = flow( | |
on('message'), | |
buffer({ size: 100 }), | |
map(message => JSON.parse(message.data)), | |
filter(data => data.type === "result"), | |
); | |
let websocket = new WebSocket('wss://localhost:9000'); | |
yield* pipe(websocket, results, forEach(function*(result) { | |
console.log('received result from websocket', result) | |
})); |
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 { on, pipe } from "effection"; | |
let websocket = new WebSocket('wss://localhost:9000'); | |
yield* pipe(websocket, on("message"), forEach(function*(message) { | |
console.log('received message from websocket', message) | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment