StringSearchResult overview
Result type of the search operations exposed by {@link “./String.js” | MString}: a substring match together with the half-open [startIndex, endIndex) range it covers.
Mental model
Typeis anEqual-aware value object built on {@link “../Data/EquivalenceBasedEqualityData.js” |MEquivalenceBasedEqualityData.Class}.- Two results are equal iff their
startIndex,endIndexandmatchall coincide. - The {@link areOverlapping}
Equivalenceis 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: {@link make}
- Compare: {@link equivalence}, {@link areOverlapping}
- Order: {@link byStartIndex}, {@link byEndIndex}, {@link byLongestFirst}
- Field access: {@link startIndex}, {@link endIndex}, {@link match}
Table of contents
Constructors
make
Builds a search result.
Signature
export 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 {@link equivalence} for that.
Signature
export 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
export declare const equivalence: Equivalence.Equivalence<Type>
Getters
endIndex
Returns the endIndex field of self.
Signature
export declare const endIndex: MTypes.OneArgFunction<Type, number>
match
Returns the match field of self.
Signature
export declare const match: MTypes.OneArgFunction<Type, string>
startIndex
Returns the startIndex field of self.
Signature
export declare const startIndex: MTypes.OneArgFunction<Type, number>
Models
Type (class)
Type of a search result: the matched substring and its [startIndex, endIndex) range.
Signature
export declare class Type {
private constructor({ startIndex, endIndex, match }: MTypes.Data<Type>)
}
make (static method)
Static constructor
Signature
static make(params: MTypes.Data<Type>): Type
[MData.idSymbol] (method)
Returns the id of this
Signature
[MData.idSymbol](): string | (() => string)
[Hash.symbol] (method)
Calculates the hash value of this
Signature
[Hash.symbol](): number
[MEquivalenceBasedEqualityData.isEquivalentToSymbol] (method)
Function that implements the equivalence of this and that
Signature
[MEquivalenceBasedEqualityData.isEquivalentToSymbol](this: this, that: this): boolean
[MEquivalenceBasedEqualityData.hasSameTypeMarkerAsSymbol] (method)
Predicate that returns true if that has the same type marker as this
Signature
[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
export declare const moduleTag: "@parischap/effect-lib/String/StringSearchResult/"
Ordering
byEndIndex
Ordering on endIndex (ascending).
Signature
export 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
export declare const byLongestFirst: Order.Order<Type>
byStartIndex
Ordering on startIndex (ascending).
Signature
export declare const byStartIndex: Order.Order<Type>