Live data from Hacker News

Show HN: A JavaScript function that looks and behaves like a pipe operator

github.com

111–120 of 148 posts

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#111
post #27

I like goofy projects like this one but I think that if you insist on having calls there, then might as well make it more explicit with something like this: pipe((p) => ([ "hello", p.concat("!"), send, p.status, console.log ])); Where `p` stands for Proxy to the previous result. Under the hood it would just return an object describing the name of the called method and arguments passed. The pipe function would then it…

[deleted]

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#112
post #63

Reminds me of something I tried hacking together in python for fun from functools import partial class Pipeable: def __init__(self, fn): self.fn = fn def __ror__(self, lhs): return self.fn(lhs) def pipeable(fn): return lambda *args: Pipeable(partial(fn, *args)) filter = pipeable(filter) map = pipeable(map) list = pipeable(list) sum = pipeable(sum) min = pipeable(min) max = pipeable(max) any = pipeable(any) # Usage: r…

Yeah, I did something similar in effect in Python some time ago: https://github.com/vollcheck/pypelines - this is a bytecode hack rather than operator overloading.

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#113
post #110
post #27

I like goofy projects like this one but I think that if you insist on having calls there, then might as well make it more explicit with something like this: pipe((p) => ([ "hello", p.concat("!"), send, p.status, console.log ])); Where `p` stands for Proxy to the previous result. Under the hood it would just return an object describing the name of the called method and arguments passed. The pipe function would then it…

Here's a very basic implementation: https://github.com/Tade0/pipe/blob/master/pipe-sync.js

Nice idea, but something as simple as this doesn't work:

    pipeSync(p => [
      "hello",
      p + " world",
      console.log
    ]);

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#115

Earlier quoted context omitted.

Tell that to Unix/FP lovers.

hahaha i mean this implementation. piping things in the shell is great

Ahh OK. Yeah, I always find trying to shoehorn language semantics via functions to be kinda awkward. The best attempt I've seen is this addition of async/await to Lua, which actually looks pretty usable [1].

[1] https://github.com/ms-jpq/lua-async-await

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#117
post #96

>The following example code is a bit hard to read: >const { status } = await send(capitalize(greeting) + "!") >console.log(status) No it's not hard to read. >Make it less nested, more vertical, by using the V "pipe": >V( greeting, // initial value "hi" >V (capitalize), // custom function call "Hi" >V .concat("!"), // String method `concat` call "Hi!" >V (send), // custom async function call Promise { } >V .status, //…

Someone decided to create a solution and then started looking for problems that will fit it. Finding none, they invented one.

For some reason I was compelled to click on your profile and noted that this your first comment after 7 years of inactivity. Welcome back

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#118
post #27

I like goofy projects like this one but I think that if you insist on having calls there, then might as well make it more explicit with something like this: pipe((p) => ([ "hello", p.concat("!"), send, p.status, console.log ])); Where `p` stands for Proxy to the previous result. Under the hood it would just return an object describing the name of the called method and arguments passed. The pipe function would then it…

Gulp[1] and node streams sortof do this

  gulp.src(config.src)
    .pipe(uglify())
    .pipe(gulp.dest(config.dest))
    .pipe(size());

[1] https://www.npmjs.com/package/gulp

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#119
post #13

The following example code is a bit hard to read: const { status } = await send(capitalize(greeting) + "!") console.log(status) I disagree, I find this example code very easy to read because it reads like idiomatic Javascript. Unlike this library.

I think the implication is that it's difficult to read because it's read non-linearly. You first need to start in the middle at `greeting`, then work your way out to `capitalize` on the left, then to `+ "!"` on the right, then work your way out one more layer to the left with `send`. Some kind of pipe operator can make this easier to read by arranging the operations linearly from left to right (or top to bottom as is…

I agree. In the example case, I don't see why left-to-right or top-to-bottom would be more readable.

Sure, it is good most of the time, but operator precedence rules exist for a reason.

I don't want to read

  2.chain(x => x * 2).chain(f)
instead of

  f(2*x)
These patterns have their place for async programming, pure FP, streams and more.

They can also be a distraction.

E.g. the library introduces its own promise-unwrapping semantics and more.

I don't see the use for such a generic implementation, although I applaud the effort.

Post reply on HN