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 they're
stuck with non-transpiled ES2015, `str.replace(/[^]/gu, m => ...)`.
-----

Isiah Meadows
[email protected]
www.isiahmeadows.com


On Thu, May 17, 2018 at 2:56 PM, Jordan Harband <[email protected]> wrote:
>> 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
> <[email protected]> wrote:
>>
>> 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!
>>
>> Regards
>>
>>
>> On Thu, May 17, 2018 at 7:12 PM, Jordan Harband <[email protected]> wrote:
>>>
>>> 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 <[email protected]> wrote:
>>>>
>>>> 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 codepoints.
>>>> Some
>>>> might even want to iterate in terms of visible glyphs, taking combining
>>>> marks
>>>> into account.
>>>>
>>>> This ambiguity makes `String.prototype.map` moot, as it remains
>>>> questionable
>>>> what exactly should be iterated. Bytes? Codepoints? Entire glyphs?
>>>>
>>>> On Thursday, May 17, 2018 5:41:32 PM CEST you wrote:
>>>> > 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
>>>> > codepoints. Some might even want to iterate in terms of visible
>>>> > glyphs,
>>>> > taking combining marks into account.
>>>> >
>>>> > This ambiguity makes `String.prototype.map` moot, as it remains
>>>> > questionable
>>>> > what exactly should be iterated. Bytes? Codepoints? Entire glyphs?
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> [email protected]
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to