Matcher

public class Matcher

Matcher is container class, responsible for storing and resolving comparators for given types.

  • Shared Matcher instance

    Declaration

    Swift

    public static var `default` = Matcher()
  • Create new clean matcher instance.

    Declaration

    Swift

    public init()
  • Creante new matcher instance, copying existing comparator from another instance.

    Declaration

    Swift

    public init(matcher: Matcher)

    Parameters

    matcher

    other matcher instance

  • Registers comparator for given type T.

    Comparator is a closure of (T,T) -> Bool.

    When several comparators for same type are registered to common Matcher instance - it will resolve the most receont one.

    Declaration

    Swift

    public func register<T>(_ valueType: T.Type, match: @escaping (T,T) -> Bool)

    Parameters

    valueType

    compared type

    match

    comparator closure

  • Register sequence comparator, based on elements comparing.

    Declaration

    Swift

    public func register<T,E>(_ valueType: T.Type, match: @escaping (E,E) -> Bool) where T: Sequence, E == T.Element

    Parameters

    valueType

    Sequence type

    match

    Element comparator closure

  • Register default comparatot for Equatable types. Required for generic mocks to work.

    Declaration

    Swift

    public func register<T>(_ valueType: T.Type) where T: Equatable

    Parameters

    valueType

    Equatable type

  • Returns comparator closure for given type (if any).

    Comparator is a closure of (T,T) -> Bool.

    When several comparators for same type are registered to common Matcher instance - it will resolve the most receont one.

    Declaration

    Swift

    public func comparator<T>(for valueType: T.Type) -> ((T,T) -> Bool)?

    Parameters

    valueType

    compared type

    Return Value

    comparator closure

  • Default Sequence comparator, compares count, and then element by element.

    Declaration

    Swift

    public func comparator<T>(for valueType: T.Type) -> ((T,T) -> Bool)? where T: Sequence

    Parameters

    valueType

    Sequence type

    Return Value

    comparator closure

  • Default Equatable comparator, compares if elements are equal.

    Declaration

    Swift

    public func comparator<T>(for valueType: T.Type) -> ((T,T) -> Bool)? where T: Equatable

    Parameters

    valueType

    Equatable type

    Return Value

    comparator closure

  • Default Equatable Sequence comparator, compares count, and then for every element equal element.

    Declaration

    Swift

    public func comparator<T>(for valueType: T.Type) -> ((T,T) -> Bool)? where T: Equatable, T: Sequence

    Parameters

    valueType

    Equatable Sequence type

    Return Value

    comparator closure