Skip to content

Infrastructure for metaprogramming in pipe/compose (await inside pipe()) #138

Open
@koraa

Description

@koraa

Provide a generalized pipe/compose metaprogramming infrastructure.

pipe.do = Tuple('do', 'fn'); // One element tuple as a tag
pipe.await = pipe.do((p, fn) => Promise.await(p));

Whenever pipe() (or compose) encounters do, it will evaluate all the functions to the left of the do statement and compose the functions to the right into a single function; passing the value and the functions into the function stored inside to.

compose(...leftFns, pipe.do(doFn), ...rightFunctions) <=> doFn(compose(...leftFns), compose(...rightFns))

We could also use a more general meta tuple that allows for generalized rewriting:

compose(...leftFns, pipe.meta(metaFn), ...rightFns) <=> metaFn(leftFns, rightFns)

In this framework do could be implemented as a special case of meta:

pipe.do = (doFn) =>
  pipe.meta((l, r) => (v) => doFn(composev(l)(v), composev(r)));

Do alone would allow for some interesting transformations on pipe; e.g. do(ifdef) would early abort pipe execution and do(map) would actually introduce loops as part of the function composition infrastructure.

Actually, I believe this would be about as general as the haskell do monad (hence the name) while staying in the fully functional framework.

This is different from the do syntax mostly because this uses explicit connectives instead of type dependent connectives as monads to (on the other hand this could be remedied with a type class).

Of course, how practical this is would have to be evaluated but the basic use case with await is in my definetly useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeThis is a tag for issues whose implementation needs a new major versionenhancementNew feature or requesthelp wantedExtra attention is neededneeds-api-design

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions