And to my understanding, `.replace` can be better optimized for that
use case - it can limit graph copying when it builds the new string,
among other things.
If they actually need something like the `.map` as proposed here, they
could just as easily do `str.replace(/./gsu, m => ...)`, or if
> We do this on our front end where we replace certain emojis with our
custom brand icons.
Seems like something `.replace` can already do for you?
On Thu, May 17, 2018 at 11:44 AM, Andrea Giammarchi <
andrea.giammar...@gmail.com> wrote:
> I agree map is not really a good fit for strings but
I agree map is not really a good fit for strings but this looks like yet
another use case for `::` operator
```js
const map = [].map;
str::map(codeUnits);
[...str]::map(codePoints);
```
Why didn't that proposal made it again? It would make *every* request to
add prototypal methods redundant!
We do this on our front end where we replace certain emojis with our custom
brand icons.
I don’t support this suggestion, though.
On Thu, May 17, 2018 at 10:12 AM Jordan Harband wrote:
> What's the use case where you'd want to map over every (character / code
> point /
What's the use case where you'd want to map over every (character / code
point / grapheme / whatever) in a string, and apply the same callback logic
to each one?
On Thu, May 17, 2018 at 9:21 AM, kdex wrote:
> Yeah; I am aware that ES2015 added measures that make it possible
Yeah; I am aware that ES2015 added measures that make it possible iterate over
codepoints, but that was not quite my point. The problem that I see is that in
some scenarios it makes sense to think of a string as an array of bytes, and
sometimes you need to iterate over a string in terms of its
On Thu, May 17, 2018 at 11:16 AM, Ben Fletcher wrote:
> Consider adding the array .map() implementation directly to the String
> prototype.
There is a big difference between mapping over an array and mapping
over a string. Arrays can hold *anything*. Strings hold only
Combining marks will continue to be an issue (as they are with iteration),
but I'd expect that code dealing with languages for which combining marks
are a significant thing wouldn't be doing this sort of mapping in the first
place, or will have language-specific rules for handling mapping with
On Thu, May 17, 2018 at 4:16 PM, Ben Fletcher wrote:
> Consider adding the array .map() implementation directly to the String
prototype.
>
> Here is a possible polyfill:
>
> String.prototype.map = function (fn) {
> return Array.prototype.map
> .call(this, fn)
On Thu, May 17, 2018 at 4:24 PM, kdex wrote:
> This idea comes from a rather ASCII-centric perspective upon strings and
will
> definitely break multi-byte characters.
No. One of the improvements to JavaScript since ES5 (you know, those things
you keep objecting to) is that strings
I think makes sense to have String.prototype.reduce too then.
17.05.2018, 17:16, "Ben Fletcher" :
> Consider adding the array .map() implementation directly to the String
> prototype.
>
> Here is a possible polyfill:
>
> String.prototype.map = function (fn) {
>
In fact there should be a common interface that iterables should implement. I
think this could have been proposed before. This way there would be not more
common methods proposals.
On may. 17 2018, at 10:16 am, Ben Fletcher wrote:
Consider adding the array .map()
This idea comes from a rather ASCII-centric perspective upon strings and will
definitely break multi-byte characters. And even if it wouldn't, your intent
might have been to do just that.
Long story short, it's debatable what exactly you want to iterate in a string,
hence such a method would
Consider adding the array .map() implementation directly to the String
prototype.
Here is a possible polyfill:
String.prototype.map = function (fn) {
return Array.prototype.map
.call(this, fn)
.join('');
}
This replaces the common pattern of splitting, mapping,
14 matches
Mail list logo