Skip to main content Link Search Menu Expand Document (external link)

StringSearchResult.ts overview

Result type of the search operations exposed by | MString``: a substring match together with the half-open [startIndex, endIndex) range it covers.

Mental model

  • Type is an Equal-aware value object built on | MEquivalenceBasedEqualityData.Class``.
  • Two results are equal iff their startIndex, endIndex and match all coincide.
  • The areOverlapping Equivalence is not an equality — two matches may overlap without being equal.
  • Three orderings are provided: by start, by end, and a “longest first” ordering useful when resolving overlapping matches.

Common tasks

  • Construct: make
  • Compare: equivalence, areOverlapping
  • Order: byStartIndex, byEndIndex, byLongestFirst
  • Field access: startIndex, endIndex, match

Exports Grouped by Category


Constructors

make

Builds a search result.

Signature

declare const make: (params: MTypes.Data<Type>) => Type

Source

Equivalences

areOverlapping

Equivalence that holds when two results’ ranges overlap (touching at a single index counts as overlapping). Not an equality; use equivalence for that.

Signature

declare const areOverlapping: Equivalence.Equivalence<Type>

Source

equivalence

Equivalence that holds when two results share startIndex, endIndex and match. This is the equivalence used by Equal.equals on instances.

Signature

declare const equivalence: Equivalence.Equivalence<Type>

Source

Getters

endIndex

Returns the endIndex field of self.

Signature

declare const endIndex: MTypes.OneArgFunction<Type, number>

Source

match

Returns the match field of self.

Signature

declare const match: MTypes.OneArgFunction<Type, string>

Source

startIndex

Returns the startIndex field of self.

Signature

declare const startIndex: MTypes.OneArgFunction<Type, number>

Source

Models

Type (class)

Type of a search result: the matched substring and its [startIndex, endIndex) range.

Signature

declare class Type {
  private constructor({ startIndex, endIndex, match }: MTypes.Data<Type>)
}

Source

make (static method)

Static constructor

Signature

declare const make: (params: MTypes.Data<Type>) => Type

Source

[MData.idSymbol] (method)

Returns the id of this

Signature

declare const [MData.idSymbol]: () => string | (() => string)

Source

[Hash.symbol] (method)

Calculates the hash value of this

Signature

declare const [Hash.symbol]: () => number

Source

[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)

Function that implements the equivalence of this and that

Signature

declare const [MEquivalenceBasedEqualityData.isEquivalentToSymbol]: (this: this, that: this) => boolean

Source

[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)

Predicate that returns true if that has the same type marker as this

Signature

declare const [MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol]: (that: unknown) => boolean

Source

startIndex (property)

The index where the match was found in the target string

Signature

readonly startIndex: number

Source

endIndex (property)

The index of the character following the match in the target string

Signature

readonly endIndex: number

Source

match (property)

The match

Signature

readonly match: string

Source

Module markers

moduleTag

Module tag.

Signature

declare const moduleTag: "@parischap/effect-lib/String/StringSearchResult/"

Source

Ordering

byEndIndex

Ordering on endIndex (ascending).

Signature

declare const byEndIndex: Order.Order<Type>

Source

byLongestFirst

Ordering that places the longest match first when two results share the same startIndex.

  • Use to disambiguate overlapping matches in favor of the most specific one.

Signature

declare const byLongestFirst: Order.Order<Type>

Source

byStartIndex

Ordering on startIndex (ascending).

Signature

declare const byStartIndex: Order.Order<Type>

Source