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
Typeis anEqual-aware value object built on|MEquivalenceBasedEqualityData.Class``.- Two results are equal iff their
startIndex,endIndexandmatchall coincide. - The
areOverlappingEquivalenceis 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
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>
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>
Getters
endIndex
Returns the endIndex field of self.
Signature
declare const endIndex: MTypes.OneArgFunction<Type, number>
match
Returns the match field of self.
Signature
declare const match: MTypes.OneArgFunction<Type, string>
startIndex
Returns the startIndex field of self.
Signature
declare const startIndex: MTypes.OneArgFunction<Type, number>
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>)
}
make (static method)
Static constructor
Signature
declare const make: (params: MTypes.Data<Type>) => Type
[MData.idSymbol] (method)
Returns the id of this
Signature
declare const [MData.idSymbol]: () => string | (() => string)
[Hash.symbol] (method)
Calculates the hash value of this
Signature
declare const [Hash.symbol]: () => number
[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)
Function that implements the equivalence of this and that
Signature
declare const [MEquivalenceBasedEqualityData.isEquivalentToSymbol]: (this: this, that: this) => boolean
[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)
Predicate that returns true if that has the same type marker as this
Signature
declare const [MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol]: (that: unknown) => boolean
startIndex (property)
The index where the match was found in the target string
Signature
readonly startIndex: number
endIndex (property)
The index of the character following the match in the target string
Signature
readonly endIndex: number
match (property)
The match
Signature
readonly match: string
Module markers
moduleTag
Module tag.
Signature
declare const moduleTag: "@parischap/effect-lib/String/StringSearchResult/"
Ordering
byEndIndex
Ordering on endIndex (ascending).
Signature
declare const byEndIndex: Order.Order<Type>
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>
byStartIndex
Ordering on startIndex (ascending).
Signature
declare const byStartIndex: Order.Order<Type>