Segments

Bindings to Segments objects produced by Intl.Segmenter.segment. A Segments instance is an object that represents the segments of a specific string, subject to the locale and options of its constructing Intl.Segmenter instance. https://tc39.es/ecma402/#sec-segments-objects.

See MDN for API details and the ECMA-402 specification for the object shape.

containing

RESCRIPT
let containing: t => segmentData

containing(segments) returns the segment data for the index supplied when iterating.

Use this when consuming Segments via iteration helpers where the index is already implied.

containingWithIndex

RESCRIPT
let containingWithIndex: (t, int) => segmentData

containingWithIndex(segments, index) returns the segment that contains index within the original string.

Examples

RESCRIPT
let segmenter = Intl.Segmenter.make(~locales=["en"], ~options={granularity: #word}) let segments = segmenter->Intl.Segmenter.segment("Hello world") Intl.Segments.containingWithIndex(segments, 0).segment == "Hello"

ignore

RESCRIPT
let ignore: t => unit

ignore(segments) ignores the provided segments and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

segmentData

RESCRIPT
type segmentData = { segment: string, index: int, isWordLike: option<bool>, input: string, }

t

RESCRIPT
type t