rocketrpc icon indicating copy to clipboard operation
rocketrpc copied to clipboard

Pipe operator

Open Buzzertech opened this issue 4 years ago • 2 comments

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.

Buzzertech avatar Mar 14 '21 18:03 Buzzertech

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

akash-joshi avatar Mar 15 '21 07:03 akash-joshi

Awesome. I would like to help with the implementation if needed. Let me know :)

Buzzertech avatar Mar 15 '21 09:03 Buzzertech

Closing this for now since this is beyond the current scope of rocketrpc.

akash-joshi avatar Feb 16 '23 15:02 akash-joshi