News for hackers. Stuff that matters.
Re:Lodash just declared issue bankruptcy and closed every is... by WirelessGigabit on Saturday September 16, 2023 @11:52PM (#37541368)
How would you abuse reduce()?
Re:Lodash just declared issue bankruptcy and closed every is... by Too on Sunday September 17, 2023 @01:35AM (#37541843)
MDN even had to make a whole chapter to discourage overuse of it.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:Lodash just declared issue bankruptcy and closed every is... by masklinn on Sunday September 17, 2023 @02:41AM (#37542168)
Using reduce to perform a map is a fun way to annoy colleagues.
Re:Lodash just declared issue bankruptcy and closed every is... by 5e92cb50239222b on Sunday September 17, 2023 @03:08AM (#37542309)
Or .map() as a for..of replacement. I always wanted V8/SpiderMonkey developers to make .map()/.reduce() "pure" in the sense of "optimizing away" the expression if its result is not assigned to anything, and see the world burn.
Re:Lodash just declared issue bankruptcy and closed every is... by Zababa on Sunday September 17, 2023 @07:56AM (#37544088)
I think .map() as a for...of replacement makes sense for simple cases. newArray = oldArray.map(el => aFunction(el)) is short, sweet and clean.
Re:Lodash just declared issue bankruptcy and closed every is... by orra on Sunday September 17, 2023 @08:14AM (#37544229)
It's definitely short, but are you doing it for the side effects? Then I find .map() misleading. I'd much prefer a .forEach(), or a for...of.
Re:Lodash just declared issue bankruptcy and closed every is... by masklinn on Sunday September 17, 2023 @08:20AM (#37544275)
If you’re mapping for side effects you deserve a good rap on the head.

The main value of “map” is to denote a 1:1 data transformation. Plus this gets very fraught with many langages mapping lazily, and some not guaranteeing the order of operation.

Re:Lodash just declared issue bankruptcy and closed every is... by pwdisswordfishc on Sunday September 17, 2023 @03:59AM (#37542621)
Use it at all, presumably.
Re:Lodash just declared issue bankruptcy and closed every is... by JuanPosadas on Sunday September 17, 2023 @07:47AM (#37544015)
I'm probably on the mild side of abusing it, I've never seen another developer on my team use it, but I also include self-describing variables for the values. If the reducer function itself is non-trivial, I've give it a name so the final product may look like:

    const idNameMap = itemList.reduce(toIdNameMap)
It should be intuitive that itemList is a list of objects familiar to the context of the code, and the result will be like:

    [{"id1":"Billy"}, etc.
Re:Lodash just declared issue bankruptcy and closed every is... by masklinn on Sunday September 17, 2023 @08:01AM (#37544123)
It’s really not clear to me what the transformation is, but from the naming and result it mostly looks like it’s an abuse of reduce and should be a map, possibly feeding into an Object / Map constructor / factory?
Re:Lodash just declared issue bankruptcy and closed every is... by yakshaving_jgt on Sunday September 17, 2023 @04:24PM (#37548962)
> It should be intuitive that itemList is a list of objects

…But how?!

I can't see how anyone could build an intuition for this opaque line and the example of its apparent result. It's confusing enough that `idNameMap` actually refers to a list (or array), and not a map (or object).