rocketrpc
rocketrpc copied to clipboard
Pipe operator
Context
I think it would be very useful for this library to support operators out of the box. An operator would be a function which can be applied on the input/output of a user defined function to get desired results. Some operators can be purely client based while some of them could be implemented on the server-side.
For example, the pipe operator for starters can be very useful. It can be used to run a series of functions on the server, which on completion returns the final result.
Sample usage (pipe operator)
import Client, { pipe, partial } from 'functions-over-websockets';
const client = Client(...);
const main = async () => {
const result = await pipe(
client.sum,
partial(client.multiply, 2),
client.square
)(2, 2);
console.log(result); // 64
}
Implementation
From what I understand - currently, the DSL is a simple object with three properties: id, params, procedureName. I think this data can be structured in a better way with a Stack wherein each item represents a function call. The pipe operator can be a metaphor for grouped calls where multiple calls are passed in the same stack. Single function calls can also follow the same DSL and pass single element in an array.
Wow, thanks for the extremely detailed question. This should be interesting to implement :))
I was looking at implementing function currying so this should be useful
Awesome. I would like to help with the implementation if needed. Let me know :)
Closing this for now since this is beyond the current scope of rocketrpc.