Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@Lensflare only when you need to use .map on a empty array with x size.
Array(800).fill(0,0).map((_,i)=>i)
Returns an array [0,1,...,798,799] -
@melezorus34
In that case it would be better to create a range and map it to an array.
Filling an array from a specified index to the end with a repeated specified value seems such a niche use case. -
@Lensflare look i couldn't find a reason to create an array at all so i made it up, ok? 😂
Maybe ppl use it with typed arrays or sth -
@bittersweet Unfold is done by passing the iterator obtained from a generator to a collection constructor. It is obviously trivial and needs no explanation.
-
@Oktokolo I would say that it's not trivial, but rather impossible to fit all kinds of morphisms in this graphic.
Technically, the picture is also wrong, because it suggests that the type signature for filter is that it takes A, when in reality it takes function A -> Bool.
But it's a good educational tool anyway 😄 -
@melezorus34 you can use it to fill an array with a particular default value, like say "grey" in an array of colours or "home" in a list of urls. There are other ways but that works
-
@melezorus34 alternatively it can use it to initialise a list of values before you have actual values so maybe you have no data until 7th item so all before are negative 1 or smth. Then later if you get the data you could still fill it out so array is useful. Idk, there are loads of usages imo, though none you couldn't do with a loop.
❤️ Check this out:
random