MatchResult
public enum MatchResult<T>
Whenever a match operation is performed, the result is going to be a MatchResult
instance.
-
The input could not be matched
Declaration
Swift
case noMatch
-
The input can match, if it were continued. (It’s the prefix of the matching expression)
Declaration
Swift
case possibleMatch
-
The input matches the expression. It provides information about the
length
of the matched input, theoutput
after the evaluation, and thevariables
that were processed during the process.Declaration
Swift
case exactMatch(length: Int, output: T, variables: [String : Any])
Parameters
length
The length of the match in the input string
output
The interpreted content
variables
The key-value pairs of the found
Variable
instances along the way -
In case the matching sequence only consists of one variable, the result is going to be anyMatch
Declaration
Swift
case anyMatch(exhaustive: Bool)
Parameters
exhaustive
Whether the matching should be exaustive or just return the shortest matching result
-
Shorter syntax for pattern matching
MatchResult.exactMatch
Declaration
Swift
func isMatch() -> Bool
Return Value
Whether the case of the current instance is
exactMatch
-
Shorter syntax for pattern matching
MatchResult.anyMatch
Declaration
Swift
func isAnyMatch(exhaustive: Bool = false) -> Bool
Parameters
exhaustive
If the result is
anyMatch
, this one filter the content by its exhaustive parameter - if provided. Usesfalse
otherwiseReturn Value
Whether the case of the current instance is
anyMatch
-
Shorter syntax for pattern matching
MatchResult.noMatch
Declaration
Swift
func isNoMatch() -> Bool
Return Value
Whether the case of the current instance is
noMatch
-
Shorter syntax for pattern matching
MatchResult.anypossibleMatch
Declaration
Swift
func isPossibleMatch() -> Bool
Return Value
Whether the case of the current instance is
possibleMatch
-
MatchResult
with Equatable objects are also EquatableDeclaration
Swift
static func == (lhs: MatchResult<T>, rhs: MatchResult<T>) -> Bool
Parameters
lhs
Left hand side
rhs
Right hand side
Return Value
Whether the
MatchResult
have the same values, including the contents of their associated objects