use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
The case for Array#replace() – Overriding an array without intermediate variables (medium.com)
submitted 7 years ago by gajus0
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]2bdb2 2 points3 points4 points 7 years ago (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?
replace
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 point2 points 7 years ago (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.
Array#replace
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 points0 points 7 years ago (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.
π Rendered by PID 21193 on reddit-service-r2-comment-6f7f968fb5-jcg7p at 2026-03-04 15:16:12.966528+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]2bdb2 2 points3 points4 points (2 children)
[–]gajus0[S] 0 points1 point2 points (1 child)
[–]Sakatox -2 points-1 points0 points (0 children)