Hacker News new | ask | show | jobs
by ranting-moth 994 days ago
>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 { <pending> }
  >V .status,       // automatic promise chaining + getting property  Promise {200}
  >V (console.log), // automatic promise chaining + global function call  logs 200 )
This cursed abomination is a joke isn't it?
2 comments

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
Is functional programming a joke? YMMV...
I don't think the first example is less pure than the second, what makes you think it is?
Purely functional programming is a subset of functional programming (see F# for instance). I was referring to the pipe operator syntax common to many functional programming languages like Haskell, F#, OCaml, Elixir, Elm and so on...
Ok, you aren't arguing for 'pure' functional programming, but I think you have sidestepped my question, then:

The pipe operator is just one part of functional programming, composing and applying functions

`f(g(x))` is still functional, and I would argue it exactly what is happening in the first example.

Nobody said the first example _isn't_ functional. The point is that function composition f(g(x)) is very common in a functional paradigm and many functional languages have added a Pipeline operator as syntactic sugar for this use case.
Nobody explicitly said it wasn't functional, but the original question was "why would you do b (the 'V' shit), instead of a?" ('is this a joke?'), and the response was "well if you care about functional programming you would!" ('is functional programming a joke?'), which is heavily implying that the first example is not functional! (or 'less' functional)

That you don't recognise that is strange to me, and if after my explanation you can't understand that, I don't know what to tell you.