MatchResult

com.phasmidsoftware.matchers.Matchers.MatchResult
See theMatchResult companion object
sealed trait MatchResult[+R]

Trait to define the behavior of the result of a Match.

Type parameters

R

the type of the result.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Matchers.this.Match[R]
class Matchers.this.Unsuccessful[R, X]
class Matchers.this.Error[R]
class Matchers.this.Miss[T, R]

Members list

Value members

Abstract methods

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

Composition method. If this MatchResult is a success, then return the value of matcher m applied to the result. If this is a Miss, then return this.

Composition method. If this MatchResult is a success, then return the value of matcher m applied to the result. If this is a Miss, then return this.

Type parameters

S

the underlying type of the input to m (S is a super-class of R).

T

the underlying type of the returned value.

Value parameters

m

a call-by-name Matcher of S to T.

Attributes

Returns

a MatchResult[T].

def andThen[S](sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[R ~ S]

Method to compose this MatchResult with sm. The results of this and of sm are combined into one ~. The ~ method is a synonym of andThen.

Method to compose this MatchResult with sm. The results of this and of sm are combined into one ~. The ~ method is a synonym of andThen.

Type parameters

S

the underlying type of s.

Value parameters

sm

a call-by-name MatchResult[S].

Attributes

Returns

a MatchResult[R ~ S].

def flatMap[S](f: R => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[S]

FlatMap method. If this is a Match(r), then return f(r). Otherwise, we return an unsuccessful result based on this.

FlatMap method. If this is a Match(r), then return f(r). Otherwise, we return an unsuccessful result based on this.

Type parameters

S

the underlying type of the returned MatchResult.

Value parameters

f

a function of R => MatchResult[S].

Attributes

Returns

MatchResult[S].

def foreach(f: R => Unit): Unit

Foreach method.

Foreach method.

Value parameters

f

a function of R => Unit.

Attributes

Returns

Unit.

def get: R

Attributes

Returns

the result of the MatchResult.

Throws
Throwable

(a MatcherException) if this is not a Match.

def getOrElse[S >: R](s: => S): S

Alternative form of get such that, in the case of a Miss, the default value given by s will be returned.

Alternative form of get such that, in the case of a Miss, the default value given by s will be returned.

Type parameters

S

a super-class of R.

Value parameters

s

a call-by-name value to be used if this is unsuccessful.

Attributes

Returns

the result of the MatchResult if it's a Match, otherwise return s if it's a Miss.

def guard[S](sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[S]

Method to compose this MatchResult with sm. It this is successful, then sm will be returned. Otherwise, an Unsuccessful result will be returned.

Method to compose this MatchResult with sm. It this is successful, then sm will be returned. Otherwise, an Unsuccessful result will be returned.

Similar to ~ except that this MatchResult[R] is discarded and not part of the result. In other words, this acts purely as a guard. Synonym: &&.

Type parameters

S

the type of the resulting MatchResult.

Value parameters

sm

the MatchResult that must follow this MatchResult for a successful outcome.

Attributes

Returns

a MatchResult[S].

def identify(w: String): Matchers.this.MatchResult[R]

Identifies this MatchResult with a String. It only takes effect when this is a Miss.

Identifies this MatchResult with a String. It only takes effect when this is a Miss.

Value parameters

w

The input string to be identified and matched.

Attributes

Returns

A MatchResult representing the result of the identification process.

def invert: Matchers.this.MatchResult[R]

Inverts the result of the current MatchResult.

Inverts the result of the current MatchResult.

Attributes

Returns

A MatchResult[R] representing the inverted match outcome.

def orElse[S >: R](sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[S]

Alternation method that takes a MatchResult as the alternative.

Alternation method that takes a MatchResult as the alternative.

Type parameters

S

the type of the result and a super-type of R.

Value parameters

sm

a call-by-name MatchResult that will be used if this is empty.

Attributes

Returns

a MatchResult[S], either this (if successful) otherwise sm.

def successful: Boolean

Attributes

Returns

true if this is a Match

def |[S >: R](m: => Matchers.this.Matcher[Any, S]): Matchers.this.MatchResult[S]

Alternation method that takes a Matcher as the alternative. If this MatchResult is a miss, then return the value of m applied to the input.

Alternation method that takes a Matcher as the alternative. If this MatchResult is a miss, then return the value of m applied to the input.

Type parameters

S

the type of the result and a super-type of R.

Value parameters

m

a Matcher of Any to S.

Attributes

Returns

a MatchResult[S].

Concrete methods

def &&[S](sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[S]

Method to compose this MatchResult with sm. It this is successful, then sm will be returned. Otherwise, an Unsuccessful result will be returned.

Method to compose this MatchResult with sm. It this is successful, then sm will be returned. Otherwise, an Unsuccessful result will be returned.

Similar to ~ except that this MatchResult[R] is discarded and not part of the result. In other words, this acts purely as a guard. This method simply invokes guard(sm).

Type parameters

S

the type of the resulting MatchResult.

Value parameters

sm

the MatchResult that must follow this MatchResult for a successful outcome.

Attributes

Returns

a MatchResult[S] which is the result of calling guard(sm).

def :-(f: R => Unit): Matchers.this.MatchResult[R]
Implicitly added by MatchResultOps

This method can be pronounced as "tee" as it's like a tee in a pipe. The input and the output are identical (so it's like identity) but it has a side-effect: the function f is invoked on the matched value of r (assuming that it is a Match, otherwise f is not invoked).

This method can be pronounced as "tee" as it's like a tee in a pipe. The input and the output are identical (so it's like identity) but it has a side-effect: the function f is invoked on the matched value of r (assuming that it is a Match, otherwise f is not invoked).

Value parameters

f

a R => Unit function.

Attributes

Returns

rr unchanged.

def ::-(f: R => Unit, g: String => Unit): Matchers.this.MatchResult[R]
Implicitly added by MatchResultOps

This method can also be pronounced as "tee" as it's like a tee in a pipe. The input and the output are identical (so it's like identity) but it has a side-effect: the function f is invoked on the matched value of r, while, otherwise, the function g is invoked on the String representation of the MatchResult (a Miss or Error).

This method can also be pronounced as "tee" as it's like a tee in a pipe. The input and the output are identical (so it's like identity) but it has a side-effect: the function f is invoked on the matched value of r, while, otherwise, the function g is invoked on the String representation of the MatchResult (a Miss or Error).

Value parameters

f

a R => Unit function.

Attributes

Returns

rr unchanged.

def accumulate[S, U >: R](accumulator: (R, S) => U)(sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[U]

Method to accumulate this MatchResult[R] with a MatchResult[S], given a function which can combine the wrapped elements.

Method to accumulate this MatchResult[R] with a MatchResult[S], given a function which can combine the wrapped elements.

Type parameters

S

the underlying type of sm.

U

the underlying type of the result, which is a super-class of R.

Value parameters

accumulator

a function of type (R, S) => U.

sm

a MatchResult[S].

Attributes

Returns

a MatchResult[U].

def combine[S, U](combiner: (R, S) => U)(sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[U]

Method to combine this MatchResult[R] with a MatchResult[S], given a function which can combine the wrapped elements.

Method to combine this MatchResult[R] with a MatchResult[S], given a function which can combine the wrapped elements.

Type parameters

S

the underlying type of sm.

Value parameters

combiner

a function of type (R, S) => U.

sm

a MatchResult[U].

Attributes

Returns

a MatchResult[U].

def filter(p: R => Boolean): Matchers.this.MatchResult[R]

Filters this MatchResult with the provided predicate.

Filters this MatchResult with the provided predicate.

If this is a Miss, then it is returned as is. If this is a Match, and the given predicate p is applied to its value. If the result of applying the predicate is true, then this Match is returned. Otherwise, this method returns a Miss.

Value parameters

p

A predicate function that takes a value of type R and returns a Boolean.

Attributes

Returns

A MatchResult[R] which is either the current instance if the predicate matches, or a Miss.

def filterNot(p: R => Boolean): Matchers.this.MatchResult[R]

Filters the current MatchResult (if successful) with the provided predicate. If the predicate evaluates to false for the result of this MatchResult, the current instance is returned. Otherwise, it returns a Miss. If this is a Miss then that is returned.

Filters the current MatchResult (if successful) with the provided predicate. If the predicate evaluates to false for the result of this MatchResult, the current instance is returned. Otherwise, it returns a Miss. If this is a Miss then that is returned.

Value parameters

p

A predicate function that takes a value of type R and returns a Boolean.

Attributes

Returns

A MatchResult[R] which is either the current instance if the predicate matches, or a Miss.

def isEmpty: Boolean

Method to determine if this is unsuccessful.

Method to determine if this is unsuccessful.

Attributes

Returns

the negation of successful.

def map[S](f: R => S): Matchers.this.MatchResult[S]

Map method.

Map method.

Type parameters

S

the underlying type of the returned MatchResult.

Value parameters

f

a function of R => S.

Attributes

Returns

MatchResult[S].

def success[S](s: => S): Matchers.this.MatchResult[S]

"unit" method for a successful match.

"unit" method for a successful match.

Type parameters

S

the underlying type of the result.

Value parameters

s

the call-by-name value of the result.

Attributes

Returns

a Match[S] with value s (unless s throws an exception, in which case the result will be an Error).

def ||[S >: R](sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[S]

Alternation method that takes a MatchResult as the alternative. Identical to orElse.

Alternation method that takes a MatchResult as the alternative. Identical to orElse.

Type parameters

S

the type of the result and a super-type of R.

Value parameters

sm

a call-by-name MatchResult that will be used if this is empty.

Attributes

Returns

a MatchResult[S] which is the result of invoking orElse(sm).

def ~[S](sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[R ~ S]

Method to compose this MatchResult with sm. The results of this and of sm are combined into one ~. ~ is a synonym of andThen.

Method to compose this MatchResult with sm. The results of this and of sm are combined into one ~. ~ is a synonym of andThen.

Type parameters

S

the underlying type of s.

Value parameters

sm

a call-by-name MatchResult[S].

Attributes

Returns

a MatchResult[R ~ S].

def ~~[S](sm: => Matchers.this.MatchResult[S]): Matchers.this.MatchResult[R ~ S]

Method to compose this MatchResult with sm. If either this is a Match or sm is a Match, the result will be a Match. CONSIDER having two nested match clauses such that sm would not be evaluated if this was an Error.

Method to compose this MatchResult with sm. If either this is a Match or sm is a Match, the result will be a Match. CONSIDER having two nested match clauses such that sm would not be evaluated if this was an Error.

Type parameters

S

the underlying type of s.

Value parameters

sm

a call-by-name MatchResult[S].

Attributes

Returns

a MatchResult[R ~ S].