Matcher

com.phasmidsoftware.matchers.Matchers.Matcher
trait Matcher[-T, +R] extends T => MatchResult[R]

Trait that defines the behavior of a Matcher as a function of type T => MatchResult[R] together with other filter-monadic methods, etc...

Type parameters

R

the result type.

T

the input type.

Attributes

Graph
Supertypes
trait T => Matchers.this.MatchResult[R]
class Object
trait Matchable
class Any
Known subtypes
class Matchers.this.LoggingMatcher[T, R]
Self type
Matchers.this.Matcher[T, R]

Members list

Value members

Concrete methods

def ![S >: R](s: => S): Matchers.this.Matcher[T, S]

Defines a Matcher which reverses the sense of this Matcher.

Defines a Matcher which reverses the sense of this Matcher.

Type parameters

S

the type of both s and the result (a super-type of R).

Value parameters

s

the default result value, only to be used in the even of a Miss.

Attributes

Returns

a Matcher[T, R] that works in the opposite sense to this.

def &[S](m: Matchers.this.Matcher[R, S]): Matchers.this.Matcher[T, S]

Method to combine Matchers in the sense that, when this successfully matches a T, resulting in an R, then m is invoked on the result, such that if it is successful, we return an S.

Method to combine Matchers in the sense that, when this successfully matches a T, resulting in an R, then m is invoked on the result, such that if it is successful, we return an S.

Type parameters

S

the underlying type of the resulting Matcher.

Value parameters

m

the alternative Matcher.

Attributes

Returns

a Matcher[T, S] that will match in composition on both this and m.

def :|(name: => String)(using ml: MatchLogger): Matchers.this.Matcher[T, R]
Implicitly added by MatcherOps

Enhances a Matcher with logging functionality. This method wraps an existing Matcher in a LoggingMatcher, associating it with a descriptive name and using an implicit MatchLogger to handle logging operations.

Enhances a Matcher with logging functionality. This method wraps an existing Matcher in a LoggingMatcher, associating it with a descriptive name and using an implicit MatchLogger to handle logging operations.

Value parameters

ml

An instance of MatchLogger used for managing logging behavior.

name

A descriptive name for the matcher, supplied lazily.

Attributes

Returns

A new Matcher[T, R] instance enhanced with logging capabilities.

def <~[P, S](m: Matchers.this.Matcher[P, S]): Matchers.this.Matcher[T ~ P, R]

Method to combine Matchers this and m such that the resulting Matcher takes a ~ and returns the result from this. The resulting Matcher is named "<~"

Method to combine Matchers this and m such that the resulting Matcher takes a ~ and returns the result from this. The resulting Matcher is named "<~"

Type parameters

P

the input type of m.

S

the result type of m.

Value parameters

m

a Matcher[P, S]

Attributes

Returns

a Matcher[(T, P), R] that is the result of invoking ~ but stripping the second element of the ~.

def ?: Matchers.this.Matcher[T, Option[R]]

Defines a Matcher that optionally matches what this Matcher matches. Essentially a synonym for method opt.

Defines a Matcher that optionally matches what this Matcher matches. Essentially a synonym for method opt.

Attributes

Returns

opt(this)

def ^^[S](f: R => S): Matchers.this.Matcher[T, S]

Method to transform a MatchResult with a function f.

Method to transform a MatchResult with a function f.

The matcher p ^^ f: succeeds if p succeeds; The resulting match will be the result of applying function f to the result of invoking p.

Value parameters

f

a function that will be applied to this matcher's result (see method map in MatchResult).

Attributes

Returns

a parser that has the same behavior as the current matcher, but whose result is transformed by f.

def chain[Q, U](m: Matchers.this.Matcher[(Q, R), U]): Matchers.this.Matcher[(Q, T), U]

CONSIDER maybe doesn't make sense (compare with valve).

CONSIDER maybe doesn't make sense (compare with valve).

Matcher which succeeds or not, depending on an additional Q value (the control).

Type parameters

Q

the type of the control value.

U

the result type of m and the returned Matcher.

Value parameters

m

a Matcher[(Q, R),U].

Attributes

Returns

a Matcher[(Q,T),U].

def flatMap[U <: T, S](f: R => Matchers.this.MatchResult[S]): Matchers.this.Matcher[U, S]

Map method that transforms this Matcher[T, R] into a Matcher[U, S].

Map method that transforms this Matcher[T, R] into a Matcher[U, S].

Type parameters

S

the result type for the resulting Matcher.

U

the input type for the resulting Matcher (U is a subtype of T).

Value parameters

f

a function R => S.

Attributes

Returns

a Matcher[T, S].

def map[U <: T, S](f: R => S): Matchers.this.Matcher[U, S]

Map method that transforms this Matcher[T, R] into a Matcher[T, S].

Map method that transforms this Matcher[T, R] into a Matcher[T, S].

Type parameters

S

the result type for the resulting Matcher.

U

the input type for the resulting Matcher (U is a subtype of T).

Value parameters

f

a function R => S.

Attributes

Returns

a Matcher[U, S].

def named(n: String): Matchers.this.Matcher[T, R]

Method to create a new (equivalent) Matcher to this, but with a different (given) name.

Method to create a new (equivalent) Matcher to this, but with a different (given) name.

Value parameters

n

the name of the resulting Matcher.

Attributes

Returns

a Matcher[T, R] that behaves the same as this, but which is identified by n.

override def toString: String

Returns a string representation of the Matcher instance.

Returns a string representation of the Matcher instance.

Attributes

Returns

the name of the Matcher.

Definition Classes
Function1 -> Any
def trial: Matchers.this.Matcher[T, Try[R]]

Matcher which always succeeds (unless this causes an Error) but whose result is based on a Try[R]. CONSIDER there are similarities between this and the valve method, as well as between this and the matchTryFunc method. TESTME more

Matcher which always succeeds (unless this causes an Error) but whose result is based on a Try[R]. CONSIDER there are similarities between this and the valve method, as well as between this and the matchTryFunc method. TESTME more

Attributes

Returns

Matcher[T, Try of R]

def unit[S](s: S): Matchers.this.Matcher[T, S]

Unit method that yields a Matcher

Unit method that yields a Matcher

Type parameters

S

the result type for the resulting Matcher.

Value parameters

s

the instance of type S that will be wrapped in Match for the result of the resulting Matcher.

Attributes

Returns

a Matcher[T, S].

def |[U <: T, S >: R](m: Matchers.this.Matcher[U, S]): Matchers.this.Matcher[U, S]

Method to combine Matchers in the sense that, if this fails, then we try to match using m. In other words, this defines an alternation matcher.

Method to combine Matchers in the sense that, if this fails, then we try to match using m. In other words, this defines an alternation matcher.

NOTE: changed the logic to avoid using match2Any because it is unnecessarily convoluted.

NOTE: if equals is not properly implemented for type T, it is possible to get into an infinite recursion. This is actually Issue #14.

NOTE: self-referential matchers via | will cause a StackOverflowError; no lightweight fix is known

Value parameters

m

the alternative Matcher.

Attributes

Returns

a Matcher[T, R] that will match either on this or on m.

def ~[P, S](m: Matchers.this.Matcher[P, S]): Matchers.this.Matcher[T ~ P, R ~ S]

Method to combine Matchers this and m such that the resulting Matcher takes a ~ and results in a ~. The result is named "~"

Method to combine Matchers this and m such that the resulting Matcher takes a ~ and results in a ~. The result is named "~"

Type parameters

P

the input type of m.

S

the result type of m.

Value parameters

m

a Matcher[P, S]

Attributes

Returns

a Matcher[T ~ P, R ~ S] that is the result of invoking match2All(this, m).

def ~>[P, S](m: Matchers.this.Matcher[P, S]): Matchers.this.Matcher[T ~ P, S]

Method to combine Matchers this and m such that the resulting Matcher takes a ~ and returns the result from m. The resulting Matcher is named "~>"

Method to combine Matchers this and m such that the resulting Matcher takes a ~ and returns the result from m. The resulting Matcher is named "~>"

Type parameters

P

the input type of m.

S

the result type of m.

Value parameters

m

a Matcher[P, S]

Attributes

Returns

a Matcher[(T, P), S] that is the result of invoking ~ but stripping the first element of the ~.

Inherited methods

def andThen[A](g: Matchers.this.MatchResult[R] => A): T => A

Composes two instances of Function1 in a new Function1, with this function applied first.

Composes two instances of Function1 in a new Function1, with this function applied first.

Type parameters

A

the result type of function g

Value parameters

g

a function R => A

Attributes

Returns

a new function f such that f(x) == g(apply(x))

Inherited from:
Function1
def compose[A](g: A => T): A => Matchers.this.MatchResult[R]

Composes two instances of Function1 in a new Function1, with this function applied last.

Composes two instances of Function1 in a new Function1, with this function applied last.

Type parameters

A

the type to which function g can be applied

Value parameters

g

a function A => T1

Attributes

Returns

a new function f such that f(x) == apply(g(x))

Inherited from:
Function1

Inherited and Abstract methods

def apply(v1: T): Matchers.this.MatchResult[R]

Applies the body of this function to the argument.

Applies the body of this function to the argument.

Value parameters

v1

the function argument

Attributes

Returns

the result of function application.

Inherited from:
Function1

Concrete fields

protected val name: String

A protected field representing the name of the Matcher. It provides a string identifier for the specific Matcher instance. This value is immutable and cannot be modified after initialization.

A protected field representing the name of the Matcher. It provides a string identifier for the specific Matcher instance. This value is immutable and cannot be modified after initialization.

Attributes