Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Join elements into a single string without .toArray() #294

@tats-u

Description

@tats-u

Some other languages provide a way to join elements into a single string without having to convert the iterator to an array.
It is disappointing that this proposal does not provide a similar API.

  • Java Stream API: iterator.collect(Collectors.joining(delimiter))
  • Kotlin: iterator.joinToString(delimiter)
  • C#/VB LINQ: String.Join("delimiter", iterator)

With the current specification, we have to call .toArray().join(). If JS engines do not estimate the length of the result string in advance, this array allocation is extra and unnecessary. They should.


P.S.

  • Users may expect that the iterator has .join method like arrays or the above languages
  • .toArray() in .toArray().join() is a little bit verbose and looks like a little boilerplate

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions