Skip to content

%IntlSegmentsPrototype%.values() #945

Open
@rauschma

Description

Use case

Example where Intl.Segmenter is a bit verbose:

const segmenter = new Intl.Segmenter('en-us', { granularity: 'word' });
const segments = segmenter.segment('How are you?');
console.log(
  Iterator.from(segments).filter(x => x.isWordLike).map(x => x.segment).toArray()
  // Alternative:
  // segments[Symbol.iterator]().filter(x => x.isWordLike).map(x => x.segment).toArray()
);

Solution

Add a method (e.g.) called .values() to %IntlSegmentsPrototype% that returns this[Symbol.iterator]().

segments.values().filter(x => x.isWordLike).map(x => x.segment).toArray()

Almost all other built-in iterables have string-keyed methods that return iterators, so this addition would bring %IntlSegmentsPrototype% into the fold.

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