String identity template tag

Isiah Meadows isiahmeadows at gmail.com
Fri Dec 14 17:50:42 UTC 2018


I'll point out Kai could be on to something, although I disagree `zip`
would be the right abstraction. Maybe `Array.interleave(...arrays)`? You
could do `Array.interleave(template, args).map(String).join("")` for
similar effect, and it'd be more generally useful.

The key here is that iteration would stop after the index hits any array's
length, so it'd be polyfilled kinda like this:

```js
Array.interpolate = (...args) => {
    let ret = []
    let lengths = []
    let count = 0
    for (let i = 0; i < args.length; i++) {
        lengths[i] = args[i].count
    }
    for (let index = 0; ; index++) {
        for (let i = 0; i < args.length; i++) {
            if (index === lengths[i]) return ret
            ret[count++] = args[i][index]
        }
    }
}
```

(This could be optimized, though.)

On Thu, Dec 13, 2018 at 08:03 kai zhu <kaizhu256 at gmail.com> wrote:

> why not copy python's list-zip static-function (
> https://www.programiz.com/python-programming/methods/built-in/zip)?
>
> i'm also against the spread-operator signature.
>
> ```javascript
> // python-inspired list-zip static-function
> // List.zip(list1, list2)
> str = List.zip(
>     templateList,
>     argList
> // slice-out argList-padded undefined
> ).slice(0, -1).join("\n");
>
>
>
> // List.zip only zips up to length of list1
> // padding with undefined
>
> List.zip([1, 2, 3], ["one", "two"]);
> // [1, "one", 2, "two", 3, undefined]
>
> List.zip([1, 2], ["one", "two", "three"]);
> // [1, "one", 2, "two"]
> ```
>
>
> On Thu, Dec 13, 2018, 04:15 T.J. Crowder <tj.crowder at farsightsoftware.com>
> wrote:
>
>> In general, I think method names should be verbs in the imperative
>> tense (okay, *mood* if you like linguistic distinctions), which would
>> argue for `cook` rather than `cooked`. (`String.raw` is an unfortunate
>> exception to this rule, which has largely been used throughout the
>> standard library. Another exception is `Reflect.ownKeys`. There are
>> probably others as well, but they are exceptions, not the norm.)
>>
>> I like `cook`. It's `assemble`, but with more flavor.
>>
>> The good news here, though, is we're all talking about a name, which
>> suggests that in general people like the taste of the idea. There
>> don't seem to be concerns that it's half-baked.
>>
>> (I'll stop now.)
>>
>> -- T.J. Crowder
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181214/87c978f2/attachment.html>


More information about the es-discuss mailing list