Skip to content

Implementation of pipe with existing ECMAScript features #277

@sharshuv-quotient

Description

@sharshuv-quotient

I'm not sure if it's obvious, but it's something worth mentioning. At least for the "unary function" syntax, it is already possible to implement a pipe using functional programming principles, with a syntax that has mostly the same level of readability. RxJS are already doing that.

Here's an example of such an implementation that is supposed to work with any data type: https://stackblitz.com/edit/typescript-6z61aw?file=index.ts

Usage example:
(I'm using lodash/fp for the example)

const value = pipe([1, 2, 3], [
    map((x) => [x, x * 2]),
    flatten,
    sortBy((x) => x)
  ]
);
console.log(value); // => [1, 2, 2, 3, 4, 6]

I can understand if the proposed syntax is easier to read, and also this option only solve the case for the "unary function" proposition, but it's still something that I think is worth mentioning when thinking of how to expand the language spec.

Anyway I would love to hear some thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateDuplicate of another bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions