@@ -29,9 +29,37 @@ public func map<T, U>(_ transform: @escaping (T) async throws -> U, _ matcher: s
29
29
/// `map` works by transforming the expression to a value that the given matcher uses.
30
30
///
31
31
/// For example, you might only care that a particular property on a method equals some other value.
32
+ /// So, you could write `expect(myObject).to(map(\.someOptionalIntValue, equal(3))`.
33
+ /// This is also useful in conjunction with ``satisfyAllOf`` to do a partial equality of an object.
34
+ public func map< T, U> ( _ transform: @escaping ( T ) throws -> U ? , _ matcher: Matcher < U > ) -> Matcher < T > {
35
+ Matcher { ( received: Expression < T > ) in
36
+ try matcher. satisfies ( received. cast { value in
37
+ guard let value else { return nil }
38
+ return try transform ( value)
39
+ } )
40
+ }
41
+ }
42
+
43
+ /// `map` works by transforming the expression to a value that the given matcher uses.
44
+ ///
45
+ /// For example, you might only care that a particular property on a method equals some other value.
46
+ /// So, you could write `expect(myObject).to(map(\.someOptionalIntValue, equal(3))`.
47
+ /// This is also useful in conjunction with ``satisfyAllOf`` to do a partial equality of an object.
48
+ public func map< T, U> ( _ transform: @escaping ( T ) async throws -> U ? , _ matcher: some AsyncableMatcher < U > ) -> AsyncMatcher < T > {
49
+ AsyncMatcher { ( received: AsyncExpression < T > ) in
50
+ try await matcher. satisfies ( received. cast { value in
51
+ guard let value else { return nil }
52
+ return try await transform ( value)
53
+ } )
54
+ }
55
+ }
56
+
57
+ /// `compactMap` works by transforming the expression to a value that the given matcher uses.
58
+ ///
59
+ /// For example, you might only care that a particular property on a method equals some other value.
32
60
/// So, you could write `expect(myObject).to(compactMap({ $0 as? Int }, equal(3))`.
33
61
/// This is also useful in conjunction with ``satisfyAllOf`` to match against a converted type.
34
- public func map < T, U> ( _ transform: @escaping ( T ) throws -> U ? , _ matcher: Matcher < U > ) -> Matcher < T > {
62
+ public func compactMap < T, U> ( _ transform: @escaping ( T ) throws -> U ? , _ matcher: Matcher < U > ) -> Matcher < T > {
35
63
Matcher { ( received: Expression < T > ) in
36
64
let message = ExpectationMessage . expectedTo ( " Map from \( T . self) to \( U . self) " )
37
65
@@ -47,12 +75,12 @@ public func map<T, U>(_ transform: @escaping (T) throws -> U?, _ matcher: Matche
47
75
}
48
76
}
49
77
50
- /// `map ` works by transforming the expression to a value that the given matcher uses.
78
+ /// `compactMap ` works by transforming the expression to a value that the given matcher uses.
51
79
///
52
80
/// For example, you might only care that a particular property on a method equals some other value.
53
81
/// So, you could write `expect(myObject).to(compactMap({ $0 as? Int }, equal(3))`.
54
82
/// This is also useful in conjunction with ``satisfyAllOf`` to match against a converted type.
55
- public func map < T, U> ( _ transform: @escaping ( T ) async throws -> U ? , _ matcher: some AsyncableMatcher < U > ) -> AsyncMatcher < T > {
83
+ public func compactMap < T, U> ( _ transform: @escaping ( T ) async throws -> U ? , _ matcher: some AsyncableMatcher < U > ) -> AsyncMatcher < T > {
56
84
AsyncMatcher { ( received: AsyncExpression < T > ) in
57
85
let message = ExpectationMessage . expectedTo ( " Map from \( T . self) to \( U . self) " )
58
86
0 commit comments