File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -64,5 +64,29 @@ ${Test}.test("flatMap/${Kind}/Lazy") {
64
64
+ "once per element")
65
65
% end
66
66
}
67
+
68
+ for test in flatMapToOptionalTests {
69
+ let s = ${Minimal}<OpaqueValue<Int>>(elements:
70
+ test.sequence.map(OpaqueValue.init))
71
+ let closureLifetimeTracker = LifetimeTracked(0)
72
+ var timesClosureWasCalled = 0
73
+
74
+ var result = s.lazy.flatMap {
75
+ (element: OpaqueValue<Int>) -> OpaqueValue<Int32>? in
76
+ _blackHole(closureLifetimeTracker)
77
+ timesClosureWasCalled += 1
78
+ return test.transform(element.value).map(OpaqueValue.init)
79
+ }
80
+ expectEqual(0, timesClosureWasCalled, "unexpected eagerness")
81
+
82
+ let expected = test.expected.map(OpaqueValue.init)
83
+ expectEqualSequence(
84
+ expected, result,
85
+ stackTrace: SourceLocStack().with(test.loc)
86
+ ) { $0.value == $1.value }
87
+ expectEqual(
88
+ test.sequence.count, timesClosureWasCalled,
89
+ "iterating lazy flatMap() should call closure once per element")
90
+ }
67
91
}
68
92
% end
You can’t perform that action at this time.
0 commit comments