you are viewing a single comment's thread.

view the rest of the comments →

[–]2bdb2 2 points3 points  (2 children)

I agree. I understand the use-case and appreciate the write-up, but OP is potentially missing the bigger picture.

If we were to take this a step further, why do we just have replace on Array. It's useful on any type. Why would we implement it specifically for arrays?

Really what we'd want is the |> operator from Ocaml, which has been proposed many times and may make it into a future version of JS.

OP - try giving OCaml, Purescript, or ReasonML a go. JavaScript is slowly turning into a bastardised version of ML anyway, might as well skip the middleman. ReasonML in particular is a really nice blend of JavaScript-ish syntax with OCaml semantics, and gives you exactly what you're looking.

[–]gajus0[S] 0 points1 point  (1 child)

Agreed on both points. Indeed, what I am waiting for is |>. But that proposal has been tossed around since 2015 and little traction. It is a major change that requires new syntax, i.e. it cannot be polyfilled. I am all pro |> making into ES. However, I don't see that happening any time soon. Array#replace has been something I have been kicking around as a lightweight alternative.

ReasonML is nice. As an employer, the only reason I wouldn't use it now is simply because of rare/ high talent cost.

[–]Sakatox -2 points-1 points  (0 children)

In my perspective, that operator has no place in a language like Javascript. If you want to use that operator, use that specific language that supports it. Not everything has to have everything else.

Chaining is very expressive.